Index: uspace/lib/ext4/libext4_extent.c
===================================================================
--- uspace/lib/ext4/libext4_extent.c	(revision 47faec1ce7744ac7f8f741d27164b87b61a3511f)
+++ uspace/lib/ext4/libext4_extent.c	(revision 38384ae40b4db14e20d7a0cea4f60dfedb6a7f5f)
@@ -149,4 +149,7 @@
 }
 
+/**
+ * Binary search in extent index node
+ */
 static void ext4_extent_binsearch_idx(ext4_extent_header_t *header,
 	ext4_extent_index_t **index, uint32_t iblock)
@@ -177,4 +180,7 @@
 }
 
+/**
+ * Binary search in extent leaf node
+ */
 static void ext4_extent_binsearch(ext4_extent_header_t *header,
 		ext4_extent_t **extent, uint32_t iblock)
@@ -212,38 +218,102 @@
 }
 
+// Reading routine without saving blocks to path
+//static int ext4_extent_find_extent(ext4_filesystem_t *fs,
+//		ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_t *extent)
+//{
+//	int rc;
+//
+//	block_t* block = NULL;
+//
+//	ext4_extent_header_t *header = ext4_inode_get_extent_header(inode_ref->inode);
+//	while (ext4_extent_header_get_depth(header) != 0) {
+//
+//		ext4_extent_index_t *index;
+//		ext4_extent_binsearch_idx(header, &index, iblock);
+//
+//		uint64_t child = ext4_extent_index_get_leaf(index);
+//
+//		if (block != NULL) {
+//			block_put(block);
+//		}
+//
+//		rc = block_get(&block, fs->device, child, BLOCK_FLAGS_NONE);
+//		if (rc != EOK) {
+//			return rc;
+//		}
+//
+//		header = (ext4_extent_header_t *)block->data;
+//	}
+//
+//
+//	ext4_extent_t* tmp_extent;
+//	ext4_extent_binsearch(header, &tmp_extent, iblock);
+//
+//	memcpy(extent, tmp_extent, sizeof(ext4_extent_t));
+//
+//	return EOK;
+//}
+
 static int ext4_extent_find_extent(ext4_filesystem_t *fs,
-		ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_t **ret_extent)
+		ext4_inode_ref_t *inode_ref, uint32_t iblock, ext4_extent_path_t **ret_path)
 {
 	int rc;
 
-	block_t* block = NULL;
-
-	ext4_extent_header_t *header = ext4_inode_get_extent_header(inode_ref->inode);
-	while (ext4_extent_header_get_depth(header) != 0) {
-
-		ext4_extent_index_t *index;
-		ext4_extent_binsearch_idx(header, &index, iblock);
-
-		uint64_t child = ext4_extent_index_get_leaf(index);
-
-		if (block != NULL) {
-			block_put(block);
-		}
-
-		rc = block_get(&block, fs->device, child, BLOCK_FLAGS_NONE);
+	ext4_extent_header_t *eh =
+			ext4_inode_get_extent_header(inode_ref->inode);
+
+	uint16_t depth = ext4_extent_header_get_depth(eh);
+
+	ext4_extent_path_t *tmp_path;
+
+	// Added 2 for possible tree growing
+	tmp_path = malloc(sizeof(ext4_extent_path_t) * (depth + 2));
+	if (tmp_path == NULL) {
+		return ENOMEM;
+	}
+
+	tmp_path[0].block = inode_ref->block;
+	tmp_path[0].header = eh;
+
+	uint16_t pos = 0;
+	while (ext4_extent_header_get_depth(eh) != 0) {
+
+		ext4_extent_binsearch_idx(tmp_path[pos].header, &tmp_path[pos].index, iblock);
+
+		tmp_path[pos].depth = depth;
+		tmp_path[pos].extent = NULL;
+
+		assert(tmp_path[pos].index != NULL);
+
+		uint64_t fblock = ext4_extent_index_get_leaf(tmp_path[pos].index);
+
+		block_t *block;
+		rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);
 		if (rc != EOK) {
+			// TODO cleanup
+			EXT4FS_DBG("ERRRR");
 			return rc;
 		}
 
-		header = (ext4_extent_header_t *)block->data;
-	}
-
-
-	ext4_extent_t *extent = NULL;
-	ext4_extent_binsearch(header, &extent, iblock);
-	*ret_extent = extent;
+		pos++;
+
+		eh = (ext4_extent_header_t *)block->data;
+		tmp_path[pos].block = block;
+		tmp_path[pos].header = eh;
+
+	}
+
+	tmp_path[pos].depth = 0;
+	tmp_path[pos].extent = NULL;
+	tmp_path[pos].index = NULL;
+
+    /* find extent */
+	ext4_extent_binsearch(tmp_path[pos].header, &tmp_path[pos].extent, iblock);
+
+	*ret_path = tmp_path;
 
 	return EOK;
 }
+
 
 int ext4_extent_find_block(ext4_filesystem_t *fs,
@@ -252,9 +322,13 @@
 	int rc;
 
-	ext4_extent_t *extent = NULL;
-	rc = ext4_extent_find_extent(fs, inode_ref, iblock, &extent);
+	ext4_extent_path_t *path;
+	rc = ext4_extent_find_extent(fs, inode_ref, iblock, &path);
 	if (rc != EOK) {
 		return rc;
 	}
+
+	uint16_t depth = path->depth;
+
+	ext4_extent_t *extent = path[depth].extent;
 
 	uint32_t phys_block;
@@ -262,96 +336,19 @@
 	phys_block -= ext4_extent_get_first_block(extent);
 
-
 	*fblock = phys_block;
 
+	// Put loaded blocks
+	// From 1 -> 0 is a block with inode data
+	for (uint16_t i = 1; i < depth; ++i) {
+		if (path[i].block) {
+			block_put(path[i].block);
+		}
+	}
+
+	// Destroy temporary data structure
+	free(path);
+
 	return EOK;
 
-
-//	ext4_extent_header_t *eh =
-//			ext4_inode_get_extent_header(inode_ref->inode);
-//
-//	uint16_t depth = ext4_extent_header_get_depth(eh);
-//
-//	ext4_extent_path_t *tmp_path;
-//
-//	// Added 2 for possible tree growing
-//	tmp_path = malloc(sizeof(ext4_extent_path_t) * (depth + 2));
-//	if (tmp_path == NULL) {
-//		*path = NULL;
-//		return ENOMEM;
-//	}
-//
-//	tmp_path[0].block = inode_ref->block;
-//	tmp_path[0].header = eh;
-//
-//	uint16_t pos = 0;
-//	while (ext4_extent_header_get_depth(eh) != 0) {
-//
-//		EXT4FS_DBG("count == \%u", ext4_extent_header_get_entries_count(eh));
-//
-//		ext4_extent_binsearch_idx(tmp_path + pos, iblock);
-//
-//		uint32_t offset = (void *)tmp_path[pos].index - (void *)EXT4_EXTENT_FIRST_INDEX(eh);
-//
-//		EXT4FS_DBG("offset = \%u", offset);
-//
-//		EXT4FS_DBG("first block = \%u, leaf = \%u",
-//				ext4_extent_index_get_first_block(tmp_path[pos].index),
-//				(uint32_t)ext4_extent_index_get_leaf(tmp_path[pos].index));
-//
-//		tmp_path[pos].depth = depth;
-//		tmp_path[pos].extent = NULL;
-//
-//		assert(tmp_path[pos].index != NULL);
-//
-//		uint64_t fblock = ext4_extent_index_get_leaf(tmp_path[pos].index);
-//
-//		EXT4FS_DBG("fblock = \%u", (uint32_t)fblock);
-//
-//		block_t *block;
-//		rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);
-//		if (rc != EOK) {
-//			// TODO cleanup
-//			EXT4FS_DBG("ERRRR");
-//			return rc;
-//		}
-//
-//		EXT4FS_DBG("block loaded");
-//
-//		pos++;
-//
-//		eh = (ext4_extent_header_t *)block->data;
-//		tmp_path[pos].block = block;
-//		tmp_path[pos].header = eh;
-//
-//	}
-//
-//	tmp_path[pos].depth = 0;
-//	tmp_path[pos].extent = NULL;
-//	tmp_path[pos].index = NULL;
-//
-//	EXT4FS_DBG("pos = \%u", pos);
-//
-//    /* find extent */
-//	ext4_extent_binsearch(tmp_path + pos, iblock);
-//
-//	EXT4FS_DBG("after binsearch in extent");
-//
-//	/* if not an empty leaf */
-//	if (tmp_path[pos].extent) {
-//		EXT4FS_DBG("nonempty leaf");
-//
-////		uint64_t fblock = ext4_extent_get_start(tmp_path[pos].extent);
-////		block_t *block;
-////		rc = block_get(&block, fs->device, fblock, BLOCK_FLAGS_NONE);
-////		if (rc != EOK) {
-////			// TODO cleanup
-////		}
-////		tmp_path[pos].block = block;
-//	}
-//
-//	*path = tmp_path;
-//
-//	return EOK;
 }
 
Index: uspace/lib/ext4/libext4_filesystem.c
===================================================================
--- uspace/lib/ext4/libext4_filesystem.c	(revision 47faec1ce7744ac7f8f741d27164b87b61a3511f)
+++ uspace/lib/ext4/libext4_filesystem.c	(revision 38384ae40b4db14e20d7a0cea4f60dfedb6a7f5f)
@@ -47,6 +47,5 @@
 	fs->device = service_id;
 
-	// TODO what does constant 2048 mean?
-	rc = block_init(EXCHANGE_SERIALIZE, fs->device, 2048);
+	rc = block_init(EXCHANGE_SERIALIZE, fs->device, 4096);
 	if (rc != EOK) {
 		return rc;
@@ -733,9 +732,33 @@
 	int rc;
 
-
-	/* TODO handle extents */
-
-
 	uint32_t fblock;
+
+	/* TODO Handle extents */
+//	if (ext4_superblock_has_feature_incompatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
+//			ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_EXTENTS)) {
+////		rc = ext4_extent_find_block(fs, inode_ref, iblock, &current_block);
+////
+////		if (rc != EOK) {
+////			return rc;
+////		}
+////
+////		*fblock = current_block;
+//
+//		// TODO release block from extents (and return fblock)
+//
+//		fblock = 0;
+//
+//		if (fblock == 0) {
+//			return EOK;
+//		}
+//
+//		return ext4_balloc_free_block(fs, inode_ref, fblock);
+//
+//		return EOK;
+//
+//	}
+
+
+
 	ext4_inode_t *inode = inode_ref->inode;
 
