Index: uspace/lib/ext4/libext4_extent.c
===================================================================
--- uspace/lib/ext4/libext4_extent.c	(revision 06d85e53f2ba96bd2ea9eae7bc274870ba1e1a85)
+++ uspace/lib/ext4/libext4_extent.c	(revision 2616a75b165da0ee8d2e5acb6dfd9732b6062375)
@@ -742,4 +742,6 @@
 		uint32_t iblock)
 {
+	EXT4FS_DBG("iblock = \%u", iblock);
+
 	int rc;
 
@@ -768,4 +770,6 @@
 	if (path_ptr == path) {
 
+		EXT4FS_DBG("splitting root with extents");
+
 		uint32_t new_fblock;
 		rc = ext4_balloc_alloc_block(inode_ref, &new_fblock);
@@ -774,4 +778,6 @@
 			return rc;
 		}
+
+		EXT4FS_DBG("alllocated block \%u for new leaf", new_fblock);
 
 		block_t *block;
@@ -792,5 +798,5 @@
 		path_ptr->block = block;
 		path_ptr->header = (ext4_extent_header_t *)block->data;
-		path_ptr->depth = ext4_extent_header_get_depth(path_ptr->header);
+		path_ptr->depth = 0;
 		path_ptr->index = NULL;
 
@@ -802,4 +808,9 @@
 		ext4_extent_header_set_max_entries_count(path_ptr->header, limit);
 
+		/* Initialize new extent */
+		ext4_extent_set_block_count(path_ptr->extent, 0);
+		ext4_extent_set_first_block(path_ptr->extent, iblock);
+		ext4_extent_set_start(path_ptr->extent, 0);
+
 		/* Modify root (in inode) */
 		path->depth = 1;
@@ -807,5 +818,5 @@
 		path->index = EXT4_EXTENT_FIRST_INDEX(path->header);
 
-		ext4_extent_header_set_depth(path->header, path_ptr->depth + 1);
+		ext4_extent_header_set_depth(path->header, 1);
 		ext4_extent_header_set_entries_count(path->header, 1);
 
@@ -818,4 +829,25 @@
 		*last_path_item = path_ptr;
 
+
+		ext4_extent_header_t *tmp_root = path->header;
+		EXT4FS_DBG("new root: items = \%u, maximum = \%u, depth = \%u", ext4_extent_header_get_entries_count(tmp_root),
+				ext4_extent_header_get_max_entries_count(tmp_root), ext4_extent_header_get_depth(tmp_root));
+
+		ext4_extent_index_t *root_idx = EXT4_EXTENT_FIRST_INDEX(path->header);
+		EXT4FS_DBG("first iblock = \%u, fblock = \%u", ext4_extent_index_get_first_block(root_idx),
+				(uint32_t)ext4_extent_index_get_leaf(root_idx));
+
+		ext4_extent_header_t *new_leaf = path_ptr->header;
+		EXT4FS_DBG("new leaf: items = \%u, maximum = \%u, depth = \%u", ext4_extent_header_get_entries_count(new_leaf),
+				ext4_extent_header_get_max_entries_count(new_leaf), ext4_extent_header_get_depth(new_leaf));
+
+		for (uint32_t j = 0; j < ext4_extent_header_get_entries_count(new_leaf); ++j) {
+			ext4_extent_t *tmp_ext = EXT4_EXTENT_FIRST(path_ptr->header) + j;
+
+			EXT4FS_DBG("item \%u, first iblock = \%u", j, ext4_extent_get_first_block(tmp_ext));
+		}
+
+
+		EXT4FS_DBG("Root block containing extents was split");
 		return EOK;
 	}
@@ -823,4 +855,6 @@
 	// TODO !!!
 //	assert(false);
+
+	EXT4FS_DBG("More complex splitting");
 
 	/* Start splitting */
@@ -862,4 +896,6 @@
 	/* If splitting reached root node */
 	if (path_ptr == path) {
+
+		EXT4FS_DBG("Splitting root");
 
 		uint32_t new_fblock;
@@ -913,6 +949,7 @@
 		*last_path_item = path_ptr;
 
-		return EOK;
-	}
+	}
+
+	EXT4FS_DBG("Finishing");
 
 	return EOK;
@@ -1031,4 +1068,10 @@
 append_extent:
 
+	/* Append extent for new block (includes tree splitting if needed) */
+	rc = ext4_extent_append_extent(inode_ref, path, &path_ptr, new_block_idx);
+	if (rc != EOK) {
+		goto finish;
+	}
+
 	phys_block = 0;
 
@@ -1037,11 +1080,4 @@
 	if (rc != EOK) {
 		EXT4FS_DBG("error in block allocation, rc = \%d", rc);
-		goto finish;
-	}
-
-	/* Append extent for new block (includes tree splitting if needed) */
-	rc = ext4_extent_append_extent(inode_ref, path, &path_ptr, new_block_idx);
-	if (rc != EOK) {
-		ext4_balloc_free_block(inode_ref, phys_block);
 		goto finish;
 	}
