提交 5fd5249a 编写于 作者: A Akira Fujita 提交者: Theodore Ts'o

ext4: Fix insertion point of extent in mext_insert_across_blocks()

If the leaf node has 2 extent space or fewer and EXT4_IOC_MOVE_EXT
ioctl is called with the file offset where after the 2nd extent
covers, mext_insert_across_blocks() always tries to insert extent into
the first extent.  As a result, the file gets corrupted because of
wrong extent order.  The patch fixes this problem.
Signed-off-by: NAkira Fujita <a-fujita@rs.jp.nec.com>
Signed-off-by: N"Theodore Ts'o" <tytso@mit.edu>
上级 731eb1a0
...@@ -252,6 +252,7 @@ mext_insert_across_blocks(handle_t *handle, struct inode *orig_inode, ...@@ -252,6 +252,7 @@ mext_insert_across_blocks(handle_t *handle, struct inode *orig_inode,
} }
o_start->ee_len = start_ext->ee_len; o_start->ee_len = start_ext->ee_len;
eblock = le32_to_cpu(start_ext->ee_block);
new_flag = 1; new_flag = 1;
} else if (start_ext->ee_len && new_ext->ee_len && } else if (start_ext->ee_len && new_ext->ee_len &&
...@@ -262,6 +263,7 @@ mext_insert_across_blocks(handle_t *handle, struct inode *orig_inode, ...@@ -262,6 +263,7 @@ mext_insert_across_blocks(handle_t *handle, struct inode *orig_inode,
* orig |------------------------------| * orig |------------------------------|
*/ */
o_start->ee_len = start_ext->ee_len; o_start->ee_len = start_ext->ee_len;
eblock = le32_to_cpu(start_ext->ee_block);
new_flag = 1; new_flag = 1;
} else if (!start_ext->ee_len && new_ext->ee_len && } else if (!start_ext->ee_len && new_ext->ee_len &&
...@@ -502,6 +504,7 @@ mext_leaf_block(handle_t *handle, struct inode *orig_inode, ...@@ -502,6 +504,7 @@ mext_leaf_block(handle_t *handle, struct inode *orig_inode,
le32_to_cpu(oext->ee_block) + oext_alen) { le32_to_cpu(oext->ee_block) + oext_alen) {
start_ext.ee_len = cpu_to_le16(le32_to_cpu(new_ext.ee_block) - start_ext.ee_len = cpu_to_le16(le32_to_cpu(new_ext.ee_block) -
le32_to_cpu(oext->ee_block)); le32_to_cpu(oext->ee_block));
start_ext.ee_block = oext->ee_block;
copy_extent_status(oext, &start_ext); copy_extent_status(oext, &start_ext);
} else if (oext > EXT_FIRST_EXTENT(orig_path[depth].p_hdr)) { } else if (oext > EXT_FIRST_EXTENT(orig_path[depth].p_hdr)) {
prev_ext = oext - 1; prev_ext = oext - 1;
...@@ -515,6 +518,7 @@ mext_leaf_block(handle_t *handle, struct inode *orig_inode, ...@@ -515,6 +518,7 @@ mext_leaf_block(handle_t *handle, struct inode *orig_inode,
start_ext.ee_len = cpu_to_le16( start_ext.ee_len = cpu_to_le16(
ext4_ext_get_actual_len(prev_ext) + ext4_ext_get_actual_len(prev_ext) +
new_ext_alen); new_ext_alen);
start_ext.ee_block = oext->ee_block;
copy_extent_status(prev_ext, &start_ext); copy_extent_status(prev_ext, &start_ext);
new_ext.ee_len = 0; new_ext.ee_len = 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册