Index: uspace/lib/ext4/libext4_ialloc.c
===================================================================
--- uspace/lib/ext4/libext4_ialloc.c	(revision e25d78c0e11f174a2859b76cd4b709fa16e03362)
+++ uspace/lib/ext4/libext4_ialloc.c	(revision 38542dcb2946dff802762528d1ad1190b481d010)
@@ -29,9 +29,8 @@
 /** @addtogroup libext4
  * @{
- */ 
-
+ */
 /**
- * @file	libext4_ialloc.c
- * @brief	Inode (de)allocation operations.
+ * @file  libext4_ialloc.c
+ * @brief I-node (de)allocation operations.
  */
 
@@ -43,10 +42,12 @@
 /** Convert i-node number to relative index in block group.
  *
- * @param sb	superblock
- * @param inode	i-node number to be converted
- * @return		index of the i-node in the block group
+ * @param sb    Superblock
+ * @param inode I-node number to be converted
+ *
+ * @return Index of the i-node in the block group
+ *
  */
 static uint32_t ext4_ialloc_inode2index_in_group(ext4_superblock_t *sb,
-		uint32_t inode)
+    uint32_t inode)
 {
 	uint32_t inodes_per_group = ext4_superblock_get_inodes_per_group(sb);
@@ -56,10 +57,12 @@
 /** Convert relative index of i-node to absolute i-node number.
  *
- * @param sb	superblock
- * @param inode	index to be converted
- * @return		absolute number of the i-node
+ * @param sb    Superblock
+ * @param inode Index to be converted
+ *
+ * @return Absolute number of the i-node
+ *
  */
 static uint32_t ext4_ialloc_index_in_group2inode(ext4_superblock_t *sb,
-		uint32_t index, uint32_t bgid)
+    uint32_t index, uint32_t bgid)
 {
 	uint32_t inodes_per_group = ext4_superblock_get_inodes_per_group(sb);
@@ -69,14 +72,15 @@
 /** Compute block group number from the i-node number.
  *
- * @param sb		superblock
- * @param inode		i-node number to be found the block group for
- * @return			block group number computed from i-node number
+ * @param sb    Superblock
+ * @param inode I-node number to be found the block group for
+ *
+ * @return Block group number computed from i-node number
+ *
  */
 static uint32_t ext4_ialloc_get_bgid_of_inode(ext4_superblock_t *sb,
-		uint32_t inode)
+    uint32_t inode)
 {
 	uint32_t inodes_per_group = ext4_superblock_get_inodes_per_group(sb);
 	return (inode - 1) / inodes_per_group;
-
 }
 
@@ -84,37 +88,35 @@
 /** Free i-node number and modify filesystem data structers.
  *
- * @param fs		filesystem, where the i-node is located
- * @param index		index of i-node to be release
- * @param is_dir	flag us for information whether i-node is directory or not
+ * @param fs     Filesystem, where the i-node is located
+ * @param index  Index of i-node to be release
+ * @param is_dir Flag us for information whether i-node is directory or not
+ *
  */
 int ext4_ialloc_free_inode(ext4_filesystem_t *fs, uint32_t index, bool is_dir)
 {
-	int rc;
-
 	ext4_superblock_t *sb = fs->superblock;
-
+	
 	/* Compute index of block group and load it */
 	uint32_t block_group = ext4_ialloc_get_bgid_of_inode(sb, index);
-
+	
 	ext4_block_group_ref_t *bg_ref;
-	rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
-	if (rc != EOK) {
-		return rc;
-	}
-
+	int rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
+	if (rc != EOK)
+		return rc;
+	
 	/* Load i-node bitmap */
 	uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap(
-			bg_ref->block_group, sb);
+	    bg_ref->block_group, sb);
 	block_t *bitmap_block;
-	rc = block_get(&bitmap_block, fs->device, bitmap_block_addr, BLOCK_FLAGS_NONE);
-	if (rc != EOK) {
-		return rc;
-	}
-
+	rc = block_get(&bitmap_block, fs->device, bitmap_block_addr,
+	    BLOCK_FLAGS_NONE);
+	if (rc != EOK)
+		return rc;
+	
 	/* Free i-node in the bitmap */
 	uint32_t index_in_group = ext4_ialloc_inode2index_in_group(sb, index);
 	ext4_bitmap_free_bit(bitmap_block->data, index_in_group);
 	bitmap_block->dirty = true;
-
+	
 	/* Put back the block with bitmap */
 	rc = block_put(bitmap_block);
@@ -124,34 +126,34 @@
 		return rc;
 	}
-
+	
 	/* If released i-node is a directory, decrement used directories count */
 	if (is_dir) {
 		uint32_t bg_used_dirs = ext4_block_group_get_used_dirs_count(
-			bg_ref->block_group, sb);
+		    bg_ref->block_group, sb);
 		bg_used_dirs--;
-		ext4_block_group_set_used_dirs_count(
-				bg_ref->block_group, sb, bg_used_dirs);
+		ext4_block_group_set_used_dirs_count(bg_ref->block_group, sb,
+		    bg_used_dirs);
 	}
-
+	
 	/* Update block group free inodes count */
 	uint32_t free_inodes = ext4_block_group_get_free_inodes_count(
-			bg_ref->block_group, sb);
+	    bg_ref->block_group, sb);
 	free_inodes++;
-	ext4_block_group_set_free_inodes_count(bg_ref->block_group,
-			sb, free_inodes);
-
+	ext4_block_group_set_free_inodes_count(bg_ref->block_group, sb,
+	    free_inodes);
+	
 	bg_ref->dirty = true;
-
+	
 	/* Put back the modified block group */
 	rc = ext4_filesystem_put_block_group_ref(bg_ref);
-	if (rc != EOK) {
-		return rc;
-	}
-
+	if (rc != EOK)
+		return rc;
+	
 	/* Update superblock free inodes count */
-	uint32_t sb_free_inodes = ext4_superblock_get_free_inodes_count(sb);
+	uint32_t sb_free_inodes =
+	    ext4_superblock_get_free_inodes_count(sb);
 	sb_free_inodes++;
 	ext4_superblock_set_free_inodes_count(sb, sb_free_inodes);
-
+	
 	return EOK;
 }
@@ -159,59 +161,56 @@
 /** I-node allocation algorithm.
  *
- * This is more simple algorithm, than Orlov allocator used in the Linux kernel
- *
- * @param fs		filesystem to allocate i-node on
- * @param index		output value - allocated i-node number
- * @param is_dir 	flag if allocated i-node will be file or directory
- * @return			error code
+ * This is more simple algorithm, than Orlov allocator used
+ * in the Linux kernel.
+ *
+ * @param fs     Filesystem to allocate i-node on
+ * @param index  Output value - allocated i-node number
+ * @param is_dir Flag if allocated i-node will be file or directory
+ *
+ * @return Error code
+ *
  */
 int ext4_ialloc_alloc_inode(ext4_filesystem_t *fs, uint32_t *index, bool is_dir)
 {
-	int rc;
-
 	ext4_superblock_t *sb = fs->superblock;
-
+	
 	uint32_t bgid = 0;
 	uint32_t bg_count = ext4_superblock_get_block_group_count(sb);
 	uint32_t sb_free_inodes = ext4_superblock_get_free_inodes_count(sb);
 	uint32_t avg_free_inodes = sb_free_inodes / bg_count;
-
+	
 	/* Try to find free i-node in all block groups */
 	while (bgid < bg_count) {
-
 		/* Load block group to check */
 		ext4_block_group_ref_t *bg_ref;
-		rc = ext4_filesystem_get_block_group_ref(fs, bgid, &bg_ref);
-		if (rc != EOK) {
+		int rc = ext4_filesystem_get_block_group_ref(fs, bgid, &bg_ref);
+		if (rc != EOK)
 			return rc;
-		}
-
+		
 		ext4_block_group_t *bg = bg_ref->block_group;
-
+		
 		/* Read necessary values for algorithm */
 		uint32_t free_blocks = ext4_block_group_get_free_blocks_count(bg, sb);
 		uint32_t free_inodes = ext4_block_group_get_free_inodes_count(bg, sb);
 		uint32_t used_dirs = ext4_block_group_get_used_dirs_count(bg, sb);
-
+		
 		/* Check if this block group is good candidate for allocation */
 		if ((free_inodes >= avg_free_inodes) && (free_blocks > 0)) {
-
 			/* Load block with bitmap */
-			uint32_t bitmap_block_addr =  ext4_block_group_get_inode_bitmap(
-					bg_ref->block_group, sb);
-
+			uint32_t bitmap_block_addr = ext4_block_group_get_inode_bitmap(
+			    bg_ref->block_group, sb);
+			
 			block_t *bitmap_block;
-			rc = block_get(&bitmap_block, fs->device,
-					bitmap_block_addr, BLOCK_FLAGS_NONE);
-			if (rc != EOK) {
+			rc = block_get(&bitmap_block, fs->device, bitmap_block_addr,
+			    BLOCK_FLAGS_NONE);
+			if (rc != EOK)
 				return rc;
-			}
-
+			
 			/* Try to allocate i-node in the bitmap */
 			uint32_t inodes_in_group = ext4_superblock_get_inodes_in_group(sb, bgid);
 			uint32_t index_in_group;
-			rc = ext4_bitmap_find_free_bit_and_set(
-					bitmap_block->data, 0, &index_in_group, inodes_in_group);
-
+			rc = ext4_bitmap_find_free_bit_and_set(bitmap_block->data,
+			    0, &index_in_group, inodes_in_group);
+			
 			/* Block group has not any free i-node */
 			if (rc == ENOSPC) {
@@ -220,17 +219,16 @@
 				continue;
 			}
-
+			
 			/* Free i-node found, save the bitmap */
 			bitmap_block->dirty = true;
-
+			
 			rc = block_put(bitmap_block);
-			if (rc != EOK) {
+			if (rc != EOK)
 				return rc;
-			}
-
+			
 			/* Modify filesystem counters */
 			free_inodes--;
 			ext4_block_group_set_free_inodes_count(bg, sb, free_inodes);
-
+			
 			/* Increment used directories counter */
 			if (is_dir) {
@@ -238,48 +236,44 @@
 				ext4_block_group_set_used_dirs_count(bg, sb, used_dirs);
 			}
-
+			
 			/* Decrease unused inodes count */
 			if (ext4_block_group_has_flag(bg,
-				EXT4_BLOCK_GROUP_ITABLE_ZEROED)) {
-
+			    EXT4_BLOCK_GROUP_ITABLE_ZEROED)) {
 				uint32_t unused =
-						ext4_block_group_get_itable_unused(bg, sb);
-
+				    ext4_block_group_get_itable_unused(bg, sb);
+				
 				uint32_t inodes_in_group =
-						ext4_superblock_get_inodes_in_group(sb, bgid);
-
+				    ext4_superblock_get_inodes_in_group(sb, bgid);
+				
 				uint32_t free = inodes_in_group - unused;
-
+				
 				if (index_in_group >= free) {
 					unused = inodes_in_group - (index_in_group + 1);
-
 					ext4_block_group_set_itable_unused(bg, sb, unused);
 				}
 			}
-
+			
 			/* Save modified block group */
 			bg_ref->dirty = true;
-
+			
 			rc = ext4_filesystem_put_block_group_ref(bg_ref);
-			if (rc != EOK) {
+			if (rc != EOK)
 				return rc;
-			}
-
+			
 			/* Update superblock */
 			sb_free_inodes--;
 			ext4_superblock_set_free_inodes_count(sb, sb_free_inodes);
-
+			
 			/* Compute the absolute i-nodex number */
 			*index = ext4_ialloc_index_in_group2inode(sb, index_in_group, bgid);
-
+			
 			return EOK;
-
 		}
-
+		
 		/* Block group not modified, put it and jump to the next block group */
 		ext4_filesystem_put_block_group_ref(bg_ref);
 		++bgid;
 	}
-
+	
 	return ENOSPC;
 }
@@ -287,3 +281,3 @@
 /**
  * @}
- */ 
+ */
