shithub: lwext4

Download patch

ref: 86b19bc444be3567974022cc76c4b58a48b500ff
parent: 698ceba63af13eaa4b4a29f7b03edefc8cc251db
author: ngkaho1234 <[email protected]>
date: Mon Oct 19 09:59:20 EDT 2015

Add support_unwritten parameter to ext4_fs_get_inode_data_block_index.

--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -1319,7 +1319,9 @@
 
 		uint32_t ll = size > (block_size - u) ? (block_size - u) : size;
 
-		r = ext4_fs_get_inode_data_block_index(&ref, sblock, &fblock);
+		r = ext4_fs_get_inode_data_block_index(&ref,
+				sblock, &fblock,
+				true);
 		if (r != EOK)
 			goto Finish;
 
@@ -1353,7 +1355,8 @@
 	while (size >= block_size) {
 
 		r = ext4_fs_get_inode_data_block_index(&ref, sblock,
-						       &fblock);
+						       &fblock,
+						       true);
 		if (r != EOK)
 			goto Finish;
 
@@ -1375,7 +1378,9 @@
 	}
 
 	if (size) {
-		r = ext4_fs_get_inode_data_block_index(&ref, sblock, &fblock);
+		r = ext4_fs_get_inode_data_block_index(&ref,
+						sblock, &fblock,
+						true);
 		if (r != EOK)
 			goto Finish;
 
--- a/lwext4/ext4_dir.c
+++ b/lwext4/ext4_dir.c
@@ -140,7 +140,9 @@
 
 		ext4_fsblk_t next_block_phys_idx;
 		int rc = ext4_fs_get_inode_data_block_index(
-		    it->inode_ref, next_block_idx, &next_block_phys_idx);
+		    it->inode_ref, next_block_idx,
+		    &next_block_phys_idx,
+		    false);
 		if (rc != EOK)
 			return rc;
 
@@ -271,7 +273,9 @@
 	bool success = false;
 	for (iblock = 0; iblock < total_blocks; ++iblock) {
 		int rc =
-		    ext4_fs_get_inode_data_block_index(parent, iblock, &fblock);
+		    ext4_fs_get_inode_data_block_index(parent,
+				    iblock, &fblock,
+				    false);
 		if (rc != EOK)
 			return rc;
 
@@ -361,7 +365,9 @@
 	for (iblock = 0; iblock < total_blocks; ++iblock) {
 		/* Load block address */
 		int rc =
-		    ext4_fs_get_inode_data_block_index(parent, iblock, &fblock);
+		    ext4_fs_get_inode_data_block_index(parent,
+				    iblock, &fblock,
+				    false);
 		if (rc != EOK)
 			return rc;
 
--- a/lwext4/ext4_dir_idx.c
+++ b/lwext4/ext4_dir_idx.c
@@ -208,7 +208,7 @@
 {
 	/* Load block 0, where will be index root located */
 	ext4_fsblk_t fblock;
-	int rc = ext4_fs_get_inode_data_block_index(dir, 0, &fblock);
+	int rc = ext4_fs_get_inode_data_block_index(dir, 0, &fblock, false);
 	if (rc != EOK)
 		return rc;
 
@@ -413,7 +413,7 @@
 
 		ext4_fsblk_t fblock;
 		int rc = ext4_fs_get_inode_data_block_index(
-		    inode_ref, next_block, &fblock);
+		    inode_ref, next_block, &fblock, false);
 		if (rc != EOK)
 			return rc;
 
@@ -490,7 +490,7 @@
 		ext4_fsblk_t block_addr;
 
 		int rc = ext4_fs_get_inode_data_block_index(
-		    inode_ref, block_idx, &block_addr);
+		    inode_ref, block_idx, &block_addr, false);
 		if (rc != EOK)
 			return rc;
 
@@ -523,7 +523,8 @@
 	ext4_fsblk_t root_block_addr;
 	int rc2;
 	int rc =
-	    ext4_fs_get_inode_data_block_index(inode_ref, 0, &root_block_addr);
+	    ext4_fs_get_inode_data_block_index(inode_ref,
+			    0, &root_block_addr, false);
 	if (rc != EOK)
 		return rc;
 
@@ -564,7 +565,8 @@
 		ext4_fsblk_t leaf_block_addr;
 
 		rc = ext4_fs_get_inode_data_block_index(
-		    inode_ref, leaf_block_idx, &leaf_block_addr);
+		    inode_ref, leaf_block_idx, &leaf_block_addr,
+		    false);
 		if (rc != EOK)
 			goto cleanup;
 
@@ -1080,7 +1082,9 @@
 	/* Get direct block 0 (index root) */
 	ext4_fsblk_t root_block_addr;
 	int rc =
-	    ext4_fs_get_inode_data_block_index(parent, 0, &root_block_addr);
+	    ext4_fs_get_inode_data_block_index(parent,
+			    0, &root_block_addr,
+			    false);
 	if (rc != EOK)
 		return rc;
 
@@ -1120,7 +1124,8 @@
 	    ext4_dir_dx_entry_get_block(dx_block->position);
 	ext4_fsblk_t leaf_block_addr;
 	rc = ext4_fs_get_inode_data_block_index(parent, leaf_block_idx,
-						&leaf_block_addr);
+						&leaf_block_addr,
+						false);
 	if (rc != EOK)
 		goto release_index;
 
@@ -1198,7 +1203,7 @@
 {
 	/* Load block 0, where will be index root located */
 	ext4_fsblk_t fblock;
-	int rc = ext4_fs_get_inode_data_block_index(dir, 0, &fblock);
+	int rc = ext4_fs_get_inode_data_block_index(dir, 0, &fblock, false);
 	if (rc != EOK)
 		return rc;
 
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -1033,7 +1033,7 @@
 	/* If inode has some blocks, get last block address + 1 */
 	if (inode_block_count > 0) {
 		int rc = ext4_fs_get_inode_data_block_index(
-		    inode_ref, inode_block_count - 1, goal);
+		    inode_ref, inode_block_count - 1, goal, false);
 		if (rc != EOK)
 			return rc;
 
@@ -1090,7 +1090,8 @@
 
 static int ext4_fs_get_inode_data_block_idx(struct ext4_inode_ref *inode_ref,
 				       uint64_t iblock, ext4_fsblk_t *fblock,
-				       bool extent_create)
+				       bool extent_create,
+				       bool support_unwritten)
 {
 	struct ext4_fs *fs = inode_ref->fs;
 
@@ -1118,7 +1119,7 @@
 		current_block = current_fsblk;
 		*fblock = current_block;
 
-		ext4_assert(*fblock);
+		ext4_assert(*fblock || support_unwritten);
 		return EOK;
 	}
 #endif
@@ -1207,10 +1208,11 @@
 
 
 int ext4_fs_get_inode_data_block_index(struct ext4_inode_ref *inode_ref,
-				       uint64_t iblock, ext4_fsblk_t *fblock)
+				       uint64_t iblock, ext4_fsblk_t *fblock,
+				       bool support_unwritten)
 {
 	return ext4_fs_get_inode_data_block_idx(inode_ref, iblock, fblock,
-			false);
+			false, support_unwritten);
 }
 
 int ext4_fs_init_inode_data_block_index(struct ext4_inode_ref *inode_ref,
@@ -1217,7 +1219,7 @@
 				       uint64_t iblock, ext4_fsblk_t *fblock)
 {
 	return ext4_fs_get_inode_data_block_idx(inode_ref, iblock, fblock,
-			true);
+			true, true);
 }
 
 int ext4_fs_set_inode_data_block_index(struct ext4_inode_ref *inode_ref,
--- a/lwext4/ext4_fs.h
+++ b/lwext4/ext4_fs.h
@@ -183,12 +183,16 @@
 
 /**@brief Get physical block address by logical index of the block.
  * @param inode_ref I-node to read block address from
- * @param iblock    Logical index of block
- * @param fblock    Output pointer for return physical block address
+ * @param iblock            Logical index of block
+ * @param fblock            Output pointer for return physical
+ *                          block address
+ * @param support_unwritten Indicate whether unwritten block range
+ *                          is supported under the current context
  * @return Error code
  */
 int ext4_fs_get_inode_data_block_index(struct ext4_inode_ref *inode_ref,
-				       uint64_t iblock, ext4_fsblk_t *fblock);
+				       uint64_t iblock, ext4_fsblk_t *fblock,
+				       bool support_unwritten);
 
 /**@brief Initialize a part of unwritten range of the inode.
  * @param inode_ref I-node to proceed on.