meta_bg feature helper functions
[lwext4.git] / lwext4 / ext4_extent.c
index ca1a636a3f3c2a156321563fb44d7b923c472dce..1793f62381bd1625791b97c4979cd02e81f3e805 100644 (file)
@@ -255,6 +255,7 @@ static void ext4_extent_binsearch(struct ext4_extent_header *header,
 int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,\r
     uint32_t *fblock)\r
 {\r
+    int rc;\r
     /* Compute bound defined by i-node size */\r
     uint64_t inode_size =\r
         ext4_inode_get_size(&inode_ref->fs->sb, inode_ref->inode);\r
@@ -285,8 +286,11 @@ int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,
         /* Load child node and set values for the next iteration */\r
         uint64_t child = ext4_extent_index_get_leaf(index);\r
 \r
-        if (block.lb_id)\r
-            ext4_block_set(inode_ref->fs->bdev, &block);\r
+        if (block.lb_id){\r
+            rc = ext4_block_set(inode_ref->fs->bdev, &block);\r
+            if(rc != EOK)\r
+                return rc;\r
+        }\r
 \r
 \r
         int rc = ext4_block_get(inode_ref->fs->bdev, &block, child);\r
@@ -313,8 +317,11 @@ int ext4_extent_find_block(struct ext4_inode_ref *inode_ref, uint32_t iblock,
     }\r
 \r
     /* Cleanup */\r
-    if (block.lb_id)\r
-        ext4_block_set(inode_ref->fs->bdev, &block);\r
+    if (block.lb_id){\r
+        rc = ext4_block_set(inode_ref->fs->bdev, &block);\r
+        if(rc != EOK)\r
+            return rc;\r
+    }\r
 \r
     return EOK;\r
 }\r
@@ -389,8 +396,11 @@ cleanup:
      * From 1: 0 is a block with inode data\r
      */\r
     for (i = 1; i < tmp_path->depth; ++i) {\r
-        if (tmp_path[i].block.lb_id)\r
-            ext4_block_set(inode_ref->fs->bdev, &tmp_path[i].block);\r
+        if (tmp_path[i].block.lb_id){\r
+            int r = ext4_block_set(inode_ref->fs->bdev, &tmp_path[i].block);\r
+            if(r != EOK)\r
+                rc = r;\r
+        }\r
     }\r
 \r
     /* Destroy temporary data structure */\r
@@ -462,9 +472,7 @@ static int ext4_extent_release_branch(struct ext4_inode_ref *inode_ref,
     if (rc != EOK)\r
         return rc;\r
 \r
-    ext4_balloc_free_block(inode_ref, fblock);\r
-\r
-    return EOK;\r
+    return ext4_balloc_free_block(inode_ref, fblock);\r
 }\r
 \r
 \r
@@ -584,14 +592,20 @@ int ext4_extent_release_blocks_from(struct ext4_inode_ref *inode_ref,
         --path_ptr;\r
     }\r
 \r
+    if(!entries)\r
+        ext4_extent_header_set_depth(path->header, 0);\r
+\r
 cleanup:\r
     /*\r
      * Put loaded blocks\r
      * starting from 1: 0 is a block with inode data\r
      */\r
     for (i = 1; i <= path->depth; ++i) {\r
-        if (path[i].block.lb_id)\r
-            ext4_block_set(inode_ref->fs->bdev, &path[i].block);\r
+        if (path[i].block.lb_id){\r
+            int r = ext4_block_set(inode_ref->fs->bdev, &path[i].block);\r
+            if(r != EOK)\r
+                rc = r;\r
+        }\r
     }\r
 \r
     /* Destroy temporary data structure */\r
@@ -637,7 +651,11 @@ static int ext4_extent_append_extent(struct ext4_inode_ref *inode_ref,
             }\r
 \r
             /* Put back not modified old block */\r
-            ext4_block_set(inode_ref->fs->bdev, &path_ptr->block);\r
+            rc = ext4_block_set(inode_ref->fs->bdev, &path_ptr->block);\r
+            if (rc != EOK) {\r
+                ext4_balloc_free_block(inode_ref, fblock);\r
+                return rc;\r
+            }\r
 \r
             /* Initialize newly allocated block and remember it */\r
             memset(block.data, 0, block_size);\r
@@ -920,8 +938,11 @@ finish:
      * starting from 1: 0 is a block with inode data\r
      */\r
     for (i = 1; i <= path->depth; ++i) {\r
-        if (path[i].block.lb_id)\r
-            ext4_block_set(inode_ref->fs->bdev, &path[i].block);\r
+        if (path[i].block.lb_id){\r
+            int r = ext4_block_set(inode_ref->fs->bdev, &path[i].block);\r
+            if(r != EOK)\r
+                rc = r;\r
+        }\r
     }\r
 \r
     /* Destroy temporary data structure */\r