Index: uspace/lib/ext4/libext4_balloc.c
===================================================================
--- uspace/lib/ext4/libext4_balloc.c	(revision b12ca161211cc9652a5fedaf484bf00025c12c06)
+++ uspace/lib/ext4/libext4_balloc.c	(revision 528e5b3e3c84e8c6ddb12307c426448d71d79329)
@@ -136,5 +136,4 @@
 	}
 
-//	EXT4FS_DBG("released block \%u (idx = \%u)", block_addr, index_in_group);
 	return EOK;
 }
@@ -191,11 +190,6 @@
 
 		goal++;
-
-//		EXT4FS_DBG("goal = \%u, inode_block_count == \%u", goal, inode_block_count);
-
 		return goal;
 	}
-
-//	EXT4FS_DBG("Inode has no blocks");
 
 	// Identify block group of inode
@@ -243,6 +237,6 @@
 	uint32_t allocated_block = 0;
 
-	uint32_t bitmap_block;
-	block_t *block;
+	uint32_t bitmap_block_addr;
+	block_t *bitmap_block;
 	uint32_t rel_block_idx = 0;
 
@@ -258,6 +252,4 @@
 	uint32_t block_group = ext4_balloc_get_bgid_of_block(fs->superblock, goal);
 	uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(fs->superblock, goal);
-//	EXT4FS_DBG("block_group = \%u, index_in_group = \%u", block_group, index_in_group);
-
 
 
@@ -273,12 +265,15 @@
 					bg_ref->block_group, block_group);
 
-	if (index_in_group < first_in_group) {
-		index_in_group = first_in_group;
+	uint32_t first_in_group_index = ext4_balloc_blockaddr2_index_in_group(
+			fs->superblock, first_in_group);
+
+	if (index_in_group < first_in_group_index) {
+		index_in_group = first_in_group_index;
 	}
 
 	// Load bitmap
-	bitmap_block = ext4_block_group_get_block_bitmap(bg_ref->block_group);
-
-	rc = block_get(&block, fs->device, bitmap_block, 0);
+	bitmap_block_addr = ext4_block_group_get_block_bitmap(bg_ref->block_group);
+
+	rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0);
 	if (rc != EOK) {
 		ext4_filesystem_put_block_group_ref(bg_ref);
@@ -287,11 +282,9 @@
 	}
 
-//	EXT4FS_DBG("bitmap loaded");
-
 	// Check if goal is free
-	if (ext4_bitmap_is_free_bit(block->data, index_in_group)) {
-		ext4_bitmap_set_bit(block->data, index_in_group);
-		block->dirty = true;
-		rc = block_put(block);
+	if (ext4_bitmap_is_free_bit(bitmap_block->data, index_in_group)) {
+		ext4_bitmap_set_bit(bitmap_block->data, index_in_group);
+		bitmap_block->dirty = true;
+		rc = block_put(bitmap_block);
 		if (rc != EOK) {
 			// TODO error
@@ -308,6 +301,4 @@
 	uint32_t blocks_in_group = ext4_superblock_get_blocks_in_group(fs->superblock, block_group);
 
-//	EXT4FS_DBG("index = \%u (goal = \%u), blocks_in_group = \%u", index_in_group, goal, blocks_in_group);
-
 	uint32_t end_idx = (index_in_group + 63) & ~63;
 	if (end_idx > blocks_in_group) {
@@ -317,9 +308,9 @@
 	// Try to find free block near to goal
 	for (uint32_t tmp_idx = index_in_group + 1; tmp_idx < end_idx; ++tmp_idx) {
-		if (ext4_bitmap_is_free_bit(block->data, tmp_idx)) {
-
-			ext4_bitmap_set_bit(block->data, tmp_idx);
-			block->dirty = true;
-			rc = block_put(block);
+		if (ext4_bitmap_is_free_bit(bitmap_block->data, tmp_idx)) {
+
+			ext4_bitmap_set_bit(bitmap_block->data, tmp_idx);
+			bitmap_block->dirty = true;
+			rc = block_put(bitmap_block);
 			if (rc != EOK) {
 				// TODO error
@@ -330,7 +321,4 @@
 					fs->superblock, tmp_idx, block_group);
 
-
-//			EXT4FS_DBG("block \%u (idx = \%u) allocated, goal = \%u", allocated_block, tmp_idx, goal);
-
 			goto success;
 		}
@@ -339,9 +327,8 @@
 
 	// Find free BYTE in bitmap
-//	EXT4FS_DBG("try find free byte in own BG");
-	rc = ext4_bitmap_find_free_byte_and_set_bit(block->data, index_in_group, &rel_block_idx, blocks_in_group);
+	rc = ext4_bitmap_find_free_byte_and_set_bit(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
 	if (rc == EOK) {
-		block->dirty = true;
-		rc = block_put(block);
+		bitmap_block->dirty = true;
+		rc = block_put(bitmap_block);
 		if (rc != EOK) {
 			// TODO error
@@ -352,15 +339,12 @@
 				fs->superblock, rel_block_idx, block_group);
 
-//		EXT4FS_DBG("block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);
-
 		goto success;
 	}
 
 	// Find free bit in bitmap
-	EXT4FS_DBG("find free bit");
-	rc = ext4_bitmap_find_free_bit_and_set(block->data, index_in_group, &rel_block_idx, blocks_in_group);
+	rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
 	if (rc == EOK) {
-		block->dirty = true;
-		rc = block_put(block);
+		bitmap_block->dirty = true;
+		rc = block_put(bitmap_block);
 		if (rc != EOK) {
 			// TODO error
@@ -371,10 +355,8 @@
 				fs->superblock, rel_block_idx, block_group);
 
-		EXT4FS_DBG("find free bit: block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);
-
 		goto success;
 	}
 
-	block_put(block);
+	block_put(bitmap_block);
 	ext4_filesystem_put_block_group_ref(bg_ref);
 
@@ -386,6 +368,4 @@
 
 	while (count > 0) {
-		EXT4FS_DBG("trying group \%u", bgid);
-
 		rc = ext4_filesystem_get_block_group_ref(fs, bgid, &bg_ref);
 		if (rc != EOK) {
@@ -395,7 +375,7 @@
 
 		// Load bitmap
-		bitmap_block = ext4_block_group_get_block_bitmap(bg_ref->block_group);
-
-		rc = block_get(&block, fs->device, bitmap_block, 0);
+		bitmap_block_addr = ext4_block_group_get_block_bitmap(bg_ref->block_group);
+
+		rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, 0);
 		if (rc != EOK) {
 			ext4_filesystem_put_block_group_ref(bg_ref);
@@ -410,13 +390,16 @@
 		blocks_in_group = ext4_superblock_get_blocks_in_group(fs->superblock, bgid);
 
-		if (index_in_group < first_in_group) {
-			index_in_group = first_in_group;
-		}
-
-//		EXT4FS_DBG("trying free byte in bg \%u", bgid);
-		rc = ext4_bitmap_find_free_byte_and_set_bit(block->data, index_in_group, &rel_block_idx, blocks_in_group);
+		first_in_group_index = ext4_balloc_blockaddr2_index_in_group(
+			fs->superblock, first_in_group);
+
+		if (index_in_group < first_in_group_index) {
+			index_in_group = first_in_group_index;
+		}
+
+
+		rc = ext4_bitmap_find_free_byte_and_set_bit(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
 		if (rc == EOK) {
-			block->dirty = true;
-			rc = block_put(block);
+			bitmap_block->dirty = true;
+			rc = block_put(bitmap_block);
 			if (rc != EOK) {
 				// TODO error
@@ -427,15 +410,12 @@
 					fs->superblock, rel_block_idx, bgid);
 
-			EXT4FS_DBG("byte: block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);
-
 			goto success;
 		}
 
 		// Find free bit in bitmap
-		rc = ext4_bitmap_find_free_bit_and_set(block->data, index_in_group, &rel_block_idx, blocks_in_group);
-//		EXT4FS_DBG("trying free bit in bg \%u", bgid);
+		rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
 		if (rc == EOK) {
-			block->dirty = true;
-			rc = block_put(block);
+			bitmap_block->dirty = true;
+			rc = block_put(bitmap_block);
 			if (rc != EOK) {
 				// TODO error
@@ -446,6 +426,4 @@
 					fs->superblock, rel_block_idx, bgid);
 
-			EXT4FS_DBG("bit: block \%u allocated, index = \%u, goal = \%u", allocated_block, rel_block_idx, goal);
-
 			goto success;
 		}
@@ -453,5 +431,5 @@
 
 		// Next group
-		block_put(block);
+		block_put(bitmap_block);
 		ext4_filesystem_put_block_group_ref(bg_ref);
 		bgid = (bgid + 1) % block_group_count;
@@ -459,12 +437,9 @@
 	}
 
-	EXT4FS_DBG("No free block found");
 	return ENOSPC;
 
 success:
-
-	;
-//	EXT4FS_DBG("returning block \%u", allocated_block);
-
+	; 	// Empty command - because of syntax
+	
 	uint32_t block_size = ext4_superblock_get_block_size(fs->superblock);
 
@@ -486,7 +461,4 @@
 	ext4_filesystem_put_block_group_ref(bg_ref);
 
-//	if (goal > 1980)
-//		EXT4FS_DBG("block \%u allocated", allocated_block);
-
 	*fblock = allocated_block;
 	return EOK;
