Index: uspace/lib/ext4/libext4_balloc.c
===================================================================
--- uspace/lib/ext4/libext4_balloc.c	(revision d2f5148d8b039190172c1b7e6c93b93b1510cc56)
+++ uspace/lib/ext4/libext4_balloc.c	(revision 4358513e5caa034eb15b20401d83004c9418add9)
@@ -40,4 +40,10 @@
 #include "libext4.h"
 
+/** Convert block address to relative index in block group.
+ *
+ * @param sb			superblock pointer
+ * @param block_addr	block number to convert
+ * @return				relative number of block
+ */
 static uint32_t ext4_balloc_blockaddr2_index_in_group(ext4_superblock_t *sb,
 		uint32_t block_addr)
@@ -54,4 +60,11 @@
 }
 
+/** Convert relative block number to absolute.
+ *
+ * @param sb			superblock pointer
+ * @param index			relative index of block in group
+ * @param bgid			index of block group
+ * @return				absolute number of block
+ */
 static uint32_t ext4_balloc_index_in_group2blockaddr(ext4_superblock_t *sb,
 		uint32_t index, uint32_t bgid)
@@ -67,4 +80,10 @@
 }
 
+/** Compute number of block group from block address.
+ *
+ * @param sb			superblock pointer
+ * @param block_addr	absolute address of block
+ * @return 				block group index
+ */
 static uint32_t ext4_balloc_get_bgid_of_block(ext4_superblock_t *sb,
 		uint32_t block_addr)
@@ -82,4 +101,10 @@
 
 
+/** Free block.
+ *
+ * @param inode_ref			inode, where the block is allocated
+ * @param block_addr		absolute block address to free
+ * @return 					error code
+ */
 int ext4_balloc_free_block(ext4_inode_ref_t *inode_ref, uint32_t block_addr)
 {
@@ -89,7 +114,9 @@
 	ext4_superblock_t *sb = fs->superblock;
 
+	// Compute indexes
 	uint32_t block_group = ext4_balloc_get_bgid_of_block(sb, block_addr);
 	uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(sb, block_addr);
 
+	// Load block group reference
 	ext4_block_group_ref_t *bg_ref;
 	rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
@@ -99,4 +126,5 @@
 	}
 
+	// Load block with bitmap
 	uint32_t bitmap_block_addr = ext4_block_group_get_block_bitmap(
 			bg_ref->block_group, sb);
@@ -108,7 +136,10 @@
 	}
 
+	// Modify bitmap
 	ext4_bitmap_free_bit(bitmap_block->data, index_in_group);
 	bitmap_block->dirty = true;
 
+
+	// Release block with bitmap
 	rc = block_put(bitmap_block);
 	if (rc != EOK) {
@@ -140,4 +171,5 @@
 	bg_ref->dirty = true;
 
+	// Release block group reference
 	rc = ext4_filesystem_put_block_group_ref(bg_ref);
 	if (rc != EOK) {
@@ -149,4 +181,11 @@
 }
 
+
+/** Free continuous set of blocks.
+ *
+ * @param inode_ref			inode, where the blocks are allocated
+ * @param first				first block to release
+ * @param count				number of blocks to release
+ */
 int ext4_balloc_free_blocks(ext4_inode_ref_t *inode_ref,
 		uint32_t first, uint32_t count)
@@ -157,4 +196,5 @@
 	ext4_superblock_t *sb = fs->superblock;
 
+	// Compute indexes
 	uint32_t block_group_first =
 			ext4_balloc_get_bgid_of_block(sb, first);
@@ -164,4 +204,5 @@
 	assert(block_group_first == block_group_last);
 
+	// Load block group reference
 	ext4_block_group_ref_t *bg_ref;
 	rc = ext4_filesystem_get_block_group_ref(fs, block_group_first, &bg_ref);
@@ -174,4 +215,6 @@
 			ext4_balloc_blockaddr2_index_in_group(sb, first);
 
+
+	// Load block with bitmap
 	uint32_t bitmap_block_addr = ext4_block_group_get_block_bitmap(
 			bg_ref->block_group, sb);
@@ -184,8 +227,9 @@
 	}
 
+	// Modify bitmap
 	ext4_bitmap_free_bits(bitmap_block->data, index_in_group_first, count);
-
 	bitmap_block->dirty = true;
 
+	// Release block with bitmap
 	rc = block_put(bitmap_block);
 	if (rc != EOK) {
@@ -217,4 +261,5 @@
 	bg_ref->dirty = true;
 
+	// Release block group reference
 	rc = ext4_filesystem_put_block_group_ref(bg_ref);
 	if (rc != EOK) {
@@ -226,4 +271,11 @@
 }
 
+/** Compute first block for data in block group.
+ *
+ * @param sb		pointer to superblock
+ * @param bg		pointer to block group
+ * @param bgid		index of block group
+ * @return			absolute block index of first block
+ */
 static uint32_t ext4_balloc_get_first_data_block_in_group(
 		ext4_superblock_t *sb, ext4_block_group_t *bg, uint32_t bgid)
@@ -256,5 +308,9 @@
 }
 
-
+/** Compute 'goal' for allocation algorithm.
+ *
+ * @param inode_ref		reference to inode, to allocate block for
+ * @return				goal block number
+ */
 static uint32_t ext4_balloc_find_goal(ext4_inode_ref_t *inode_ref)
 {
@@ -272,4 +328,5 @@
 	}
 
+	// If inode has some blocks, get last block address + 1
 	if (inode_block_count > 0) {
 
@@ -292,4 +349,5 @@
 	block_size = ext4_superblock_get_block_size(sb);
 
+	// Load block group reference
 	ext4_block_group_ref_t *bg_ref;
 	rc = ext4_filesystem_get_block_group_ref(inode_ref->fs, block_group, &bg_ref);
@@ -298,4 +356,5 @@
 	}
 
+	// Compute indexes
 	uint32_t block_group_count = ext4_superblock_get_block_group_count(sb);
 	uint32_t inode_table_first_block = ext4_block_group_get_inode_table_first_block(
@@ -304,4 +363,5 @@
 	uint32_t inode_table_bytes;
 
+	// Check for last block group
 	if (block_group < block_group_count - 1) {
 		inode_table_bytes = inodes_per_group * inode_table_item_size;
@@ -327,4 +387,10 @@
 }
 
+/** Data block allocation algorithm.
+ *
+ * @param inode_ref		inode to allocate block for
+ * @param fblock		allocated block address
+ * @return				error code
+ */
 int ext4_balloc_alloc_block(
 		ext4_inode_ref_t *inode_ref, uint32_t *fblock)
@@ -352,4 +418,5 @@
 
 
+	// Load block group reference
 	ext4_block_group_ref_t *bg_ref;
 	rc = ext4_filesystem_get_block_group_ref(inode_ref->fs, block_group, &bg_ref);
@@ -359,4 +426,5 @@
 	}
 
+	// Compute indexes
 	uint32_t first_in_group =
 			ext4_balloc_get_first_data_block_in_group(sb,
@@ -370,5 +438,5 @@
 	}
 
-	// Load bitmap
+	// Load block with bitmap
 	bitmap_block_addr = ext4_block_group_get_block_bitmap(bg_ref->block_group,
 			sb);
@@ -473,5 +541,5 @@
 		}
 
-		// Load bitmap
+		// Load block with bitmap
 		bitmap_block_addr = ext4_block_group_get_block_bitmap(
 				bg_ref->block_group, sb);
@@ -484,4 +552,5 @@
 		}
 
+		// Compute indexes
 		first_in_group = ext4_balloc_get_first_data_block_in_group(
 				sb, bg_ref->block_group, bgid);
@@ -497,5 +566,5 @@
 		}
 
-
+		// Try to find free byte in bitmap
 		rc = ext4_bitmap_find_free_byte_and_set_bit(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
 		if (rc == EOK) {
@@ -513,5 +582,5 @@
 		}
 
-		// Find free bit in bitmap
+		// Try to find free bit in bitmap
 		rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data, index_in_group, &rel_block_idx, blocks_in_group);
 		if (rc == EOK) {
@@ -529,8 +598,8 @@
 		}
 
-
-		// Next group
 		block_put(bitmap_block);
 		ext4_filesystem_put_block_group_ref(bg_ref);
+
+		// Goto next group
 		bgid = (bgid + 1) % block_group_count;
 		count--;
@@ -550,5 +619,4 @@
 
 	// Update inode blocks (different block size!) count
-
 	uint64_t ino_blocks = ext4_inode_get_blocks_count(sb, inode_ref->inode);
 	ino_blocks += block_size / EXT4_INODE_BLOCK_SIZE;
@@ -569,15 +637,24 @@
 }
 
+/** Try to allocate concrete block.
+ *
+ * @param inode_ref		inode to allocate block for
+ * @param fblock		block address to allocate
+ * @param free			output value - if target block is free
+ * @return				error code
+ */
 int ext4_balloc_try_alloc_block(ext4_inode_ref_t *inode_ref,
 		uint32_t fblock, bool *free)
 {
-	int rc;
+	int rc = EOK;
 
 	ext4_filesystem_t *fs = inode_ref->fs;
 	ext4_superblock_t *sb = fs->superblock;
 
+	// Compute indexes
 	uint32_t block_group = ext4_balloc_get_bgid_of_block(sb, fblock);
 	uint32_t index_in_group = ext4_balloc_blockaddr2_index_in_group(sb, fblock);
 
+	// Load block group reference
 	ext4_block_group_ref_t *bg_ref;
 	rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
@@ -587,4 +664,5 @@
 	}
 
+	// Load block with bitmap
 	uint32_t bitmap_block_addr = ext4_block_group_get_block_bitmap(
 			bg_ref->block_group, sb);
@@ -596,6 +674,8 @@
 	}
 
+	// Check if block is free
 	*free = ext4_bitmap_is_free_bit(bitmap_block->data, index_in_group);
 
+	// Allocate block if possible
 	if (*free) {
 		ext4_bitmap_set_bit(bitmap_block->data, index_in_group);
@@ -603,4 +683,5 @@
 	}
 
+	// Release block with bitmap
 	rc = block_put(bitmap_block);
 	if (rc != EOK) {
@@ -611,4 +692,5 @@
 	}
 
+	// If block is not free, return
 	if (!(*free)) {
 		goto terminate;
