shithub: lwext4

Download patch

ref: 698ceba63af13eaa4b4a29f7b03edefc8cc251db
parent: b768b83c4ebe8e3320cbc677c45c2ddbcde24e70
author: ngkaho1234 <[email protected]>
date: Mon Oct 19 09:38:15 EDT 2015

FIX: ext4_extent_remove_space deallocating the wrong block.

--- a/lwext4/ext4_extent_full.c
+++ b/lwext4/ext4_extent_full.c
@@ -1321,21 +1321,22 @@
 	       to_le32(ex->first_block) <= to) {
 		int32_t new_len = 0;
 		int unwritten;
-		ext4_fsblk_t start, new_start;
+		ext4_lblk_t start, new_start;
 		new_start = start = to_le32(ex->first_block);
 		len = ext4_ext_get_actual_len(ex);
 		if (start < from) {
-			start = from;
 			len -= from - start;
 			new_len = from - start;
+			start = from;
 			start_ex++;
 		}
-		if (start + len - 1 > to) {
-			len -= start + len - 1 - to;
-			new_len = start + len - 1 - to;
-			new_start += to + 1;
-			ex2 = ex;
-		}
+		/* TODO: More complicated truncate operation. */
+		/*if (start + len - 1 > to) {*/
+			/*len -= start + len - 1 - to;*/
+			/*new_len = start + len - 1 - to;*/
+			/*new_start = to + 1;*/
+			/*ex2 = ex;*/
+		/*}*/
 
 		ext4_ext_remove_blocks(inode_ref, ex, start, start + len - 1);
 		ex->first_block = to_le32(new_start);
@@ -1375,7 +1376,7 @@
 	if (!to_le16(path->header->entries_count))
 		return false;
 
-	if (path->index > EXT_LAST_INDEX(path->header))
+	if (path->index >= EXT_LAST_INDEX(path->header))
 		return false;
 
 	if (to_le32(path->index->first_block) > to)