Index: uspace/app/mkmfs/mkmfs.c
===================================================================
--- uspace/app/mkmfs/mkmfs.c	(revision 7c95d6f581cca56abbce43deed7b2c4c3e46e2b2)
+++ uspace/app/mkmfs/mkmfs.c	(revision f8dfb40e4825d7bc700afd6df75981fc2bc4c435)
@@ -1,4 +1,3 @@
 /*
- * Copyright (c) 2010 Jiri Svoboda
  * Copyright (c) 2011 Maurizio Lombardi
  * All rights reserved.
@@ -56,6 +55,6 @@
 #define USED	1
 
-#define UPPER(n, size) 			(((n) / (size)) + (((n) % (size)) != 0))
-#define NEXT_DENTRY(p, dirsize)		(p += (dirsize))
+#define UPPER(n, size) 		(((n) / (size)) + (((n) % (size)) != 0))
+#define NEXT_DENTRY(p, dirsize)	(p += (dirsize))
 
 typedef enum {
@@ -64,5 +63,5 @@
 } help_level_t;
 
-/*Generic MFS superblock*/
+/* Generic MFS superblock */
 struct mfs_sb_info {
 	uint64_t n_inodes;
@@ -84,5 +83,5 @@
 
 static void	help_cmd_mkmfs(help_level_t level);
-static int	num_of_set_bits(uint32_t n);
+static bool	is_power_of_two(uint32_t n);
 static int	init_superblock(struct mfs_sb_info *sb);
 static int	write_superblock(const struct mfs_sb_info *sbi);
@@ -118,9 +117,9 @@
 	struct mfs_sb_info sb;
 
-	/*Default is MinixFS V3*/
+	/* Default is MinixFS V3 */
 	sb.magic = MFS_MAGIC_V3;
 	sb.fs_version = 3;
 
-	/*Default block size is 4Kb*/
+	/* Default block size is 4Kb */
 	sb.block_size = MFS_MAX_BLOCKSIZE;
 	sb.dirsize = MFS3_DIRSIZE;
@@ -136,5 +135,6 @@
 
 	for (c = 0, optind = 0, opt_ind = 0; c != -1;) {
-		c = getopt_long(argc, argv, "lh12b:i:", long_options, &opt_ind);
+		c = getopt_long(argc, argv, "lh12b:i:",
+		    long_options, &opt_ind);
 		switch (c) {
 		case 'h':
@@ -169,17 +169,19 @@
 
 	if (sb.block_size < MFS_MIN_BLOCKSIZE || 
-			sb.block_size > MFS_MAX_BLOCKSIZE) {
+	    sb.block_size > MFS_MAX_BLOCKSIZE) {
 		printf(NAME ":Error! Invalid block size.\n");
 		exit(0);
-	} else if (num_of_set_bits(sb.block_size) != 1) {
-		/*Block size must be a power of 2.*/
+	} else if (!is_power_of_two(sb.block_size)) {
+		/* Block size must be a power of 2. */
 		printf(NAME ":Error! Invalid block size.\n");
 		exit(0);
 	} else if (sb.block_size > MFS_BLOCKSIZE && 
-			sb.fs_version != 3) {
-		printf(NAME ":Error! Block size > 1024 is supported by V3 filesystem only.\n");
+	    sb.fs_version != 3) {
+		printf(NAME ":Error! Block size > 1024 is "
+		    "supported by V3 filesystem only.\n");
 		exit(0);
 	} else if (sb.fs_version == 3 && sb.longnames) {
-		printf(NAME ":Error! Long filenames are supported by V1/V2 filesystem only.\n");
+		printf(NAME ":Error! Long filenames are supported "
+		    "by V1/V2 filesystem only.\n");
 		exit(0);
 	}
@@ -221,8 +223,9 @@
 	rc = block_get_nblocks(service_id, &sb.dev_nblocks);
 	if (rc != EOK) {
-		printf(NAME ": Warning, failed to obtain block device size.\n");
+		printf(NAME ": Warning, failed to obtain "
+		    "block device size.\n");
 	} else {
 		printf(NAME ": Block device has %" PRIuOFF64 " blocks.\n",
-				sb.dev_nblocks);
+		    sb.dev_nblocks);
 	}
 
@@ -232,10 +235,11 @@
 	}
 
-	/*Minimum block size is 1 Kb*/
+	/* Minimum block size is 1 Kb */
 	sb.dev_nblocks /= 2;
 
 	printf(NAME ": Creating Minix file system on device\n");
-
-	/*Initialize superblock*/
+	printf(NAME ": Writing superblock\n");
+
+	/* Initialize superblock */
 	if (init_superblock(&sb) != EOK) {
 		printf(NAME ": Error. Superblock initialization failed\n");
@@ -243,5 +247,7 @@
 	}
 
-	/*Initialize bitmaps*/
+	printf(NAME ": Initializing bitmaps\n");
+
+	/* Initialize bitmaps */
 	if (init_bitmaps(&sb) != EOK) {
 		printf(NAME ": Error. Bitmaps initialization failed\n");
@@ -249,5 +255,7 @@
 	}
 
-	/*Init inode table*/
+	printf(NAME ": Initializing the inode table\n");
+
+	/* Init inode table */
 	if (init_inode_table(&sb) != EOK) {
 		printf(NAME ": Error. Inode table initialization failed\n");
@@ -255,5 +263,7 @@
 	}
 
-	/*Make the root inode*/
+	printf(NAME ": Creating the root directory inode\n");
+
+	/* Make the root inode */
 	if (sb.fs_version == 1)
 		rc = make_root_ino(&sb);
@@ -266,5 +276,5 @@
 	}
 
-	/*Insert directory entries . and ..*/
+	/* Insert directory entries . and .. */
 	if (insert_dentries(&sb) != EOK) {
 		printf(NAME ": Error. Root directory initialization failed\n");
@@ -299,5 +309,5 @@
 
 	if (sb->fs_version != 3) {
-		/*Directory entries for V1/V2 filesystem*/
+		/* Directory entries for V1/V2 filesystem */
 		struct mfs_dentry *dentry = root_block;
 
@@ -306,10 +316,10 @@
 
 		dentry = (struct mfs_dentry *) NEXT_DENTRY(dentry_ptr,
-				sb->dirsize);
+		    sb->dirsize);
 
 		dentry->d_inum = MFS_ROOT_INO;
 		memcpy(dentry->d_name, "..\0", 3);
 	} else {
-		/*Directory entries for V3 filesystem*/
+		/* Directory entries for V3 filesystem */
 		struct mfs3_dentry *dentry = root_block;
 
@@ -318,5 +328,5 @@
 
 		dentry = (struct mfs3_dentry *) NEXT_DENTRY(dentry_ptr,
-				sb->dirsize);
+		    sb->dirsize);
 
 		dentry->d_inum = MFS_ROOT_INO;
@@ -389,5 +399,5 @@
 	ino_buf[MFS_ROOT_INO - 1].i_gid = 0;
 	ino_buf[MFS_ROOT_INO - 1].i_size = (sb->longnames ? MFSL_DIRSIZE :
-	MFS_DIRSIZE) * 2;
+	    MFS_DIRSIZE) * 2;
 	ino_buf[MFS_ROOT_INO - 1].i_mtime = sec;
 	ino_buf[MFS_ROOT_INO - 1].i_nlinks = 2;
@@ -411,5 +421,5 @@
 	int rc;
 
-	/*Compute offset of the first inode table block*/
+	/* Compute offset of the first inode table block */
 	const long itable_off = sb->zbmap_blocks + sb->ibmap_blocks + 2;
 
@@ -454,15 +464,17 @@
 
 	if (sb->longnames)
-		sb->magic = sb->fs_version == 1 ? MFS_MAGIC_V1L : MFS_MAGIC_V2L;
-
-	/*Compute the number of zones on disk*/
+		sb->magic = sb->fs_version == 1 ? MFS_MAGIC_V1L :
+		    MFS_MAGIC_V2L;
+
+	/* Compute the number of zones on disk */
 
 	if (sb->fs_version == 1) {
-		/*Valid only for MFS V1*/
+		/* Valid only for MFS V1 */
 		sb->n_zones = sb->dev_nblocks > UINT16_MAX ? 
-				UINT16_MAX : sb->dev_nblocks;
+		    UINT16_MAX : sb->dev_nblocks;
 		ind = MFS_BLOCKSIZE / sizeof(uint16_t);
 		ind2 = ind * ind;
-		sb->max_file_size = (V1_NR_DIRECT_ZONES + ind + ind2) * MFS_BLOCKSIZE;
+		sb->max_file_size = (V1_NR_DIRECT_ZONES + ind + ind2) *
+		    MFS_BLOCKSIZE;
 	} else {
 		/*Valid for MFS V2/V3*/
@@ -472,4 +484,5 @@
 		else
 			ptrsize = sizeof(uint32_t);
+
 		ind = sb->block_size / ptrsize;
 		ind2 = ind * ind;
@@ -477,5 +490,5 @@
 		sb->max_file_size = zones * sb->block_size;
 		sb->n_zones = sb->dev_nblocks > UINT32_MAX ?
-				UINT32_MAX : sb->dev_nblocks;
+		    UINT32_MAX : sb->dev_nblocks;
 
 		if (sb->fs_version == 3) {
@@ -487,5 +500,5 @@
 	}
 
-	/*Round up the number of inodes to fill block size*/
+	/* Round up the number of inodes to fill block size */
 	if (sb->n_inodes == 0)
 		inodes = sb->dev_nblocks / 3;
@@ -494,5 +507,6 @@
 
 	if (inodes % sb->ino_per_block)
-		inodes = ((inodes / sb->ino_per_block) + 1) * sb->ino_per_block;
+		inodes = ((inodes / sb->ino_per_block) + 1) *
+		    sb->ino_per_block;
 
 	if (sb->fs_version < 3)
@@ -501,21 +515,21 @@
 		sb->n_inodes = inodes > UINT32_MAX ? UINT32_MAX : inodes;
 
-	/*Compute inode bitmap size in blocks*/
+	/* Compute inode bitmap size in blocks */
 	sb->ibmap_blocks = UPPER(sb->n_inodes, sb->block_size * 8);
 
-	/*Compute inode table size*/
+	/* Compute inode table size */
 	sb->itable_size = sb->n_inodes / sb->ino_per_block;
 
-	/*Compute zone bitmap size in blocks*/
+	/* Compute zone bitmap size in blocks */
 	sb->zbmap_blocks = UPPER(sb->n_zones, sb->block_size * 8);
 
-	/*Compute first data zone position*/
+	/* Compute first data zone position */
 	sb->first_data_zone = 2 + sb->itable_size + 
-			sb->zbmap_blocks + sb->ibmap_blocks;
-
-	/*Set log2 of zone to block ratio to zero*/
+	    sb->zbmap_blocks + sb->ibmap_blocks;
+
+	/* Set log2 of zone to block ratio to zero */
 	sb->log2_zone_size = 0;
 
-	/*Check for errors*/
+	/* Check for errors */
 	if (sb->first_data_zone >= sb->n_zones) {
 		printf(NAME ": Error! Insufficient disk space");
@@ -523,5 +537,5 @@
 	}
 
-	/*Superblock is now ready to be written on disk*/
+	/* Superblock is now ready to be written on disk */
 	printf(NAME ": %d block size\n", sb->block_size);
 	printf(NAME ": %d inodes\n", (uint32_t) sb->n_inodes);
@@ -530,5 +544,5 @@
 	printf(NAME ": inode bitmap blocks = %ld\n", sb->ibmap_blocks);
 	printf(NAME ": zone bitmap blocks = %ld\n", sb->zbmap_blocks);
-	printf(NAME ": first data zone = %d\n", (uint32_t) sb->first_data_zone);
+	printf(NAME ": first data zone = %d\n", (uint32_t)sb->first_data_zone);
 	printf(NAME ": max file size = %u\n", sb->max_file_size);
 	printf(NAME ": long fnames = %s\n", sb->longnames ? "Yes" : "No");
@@ -645,5 +659,5 @@
 	for (i = 0; i < ibmap_nblocks; ++i) {
 		if ((rc = write_block(start_block + i,
-				1, (ibmap_buf8 + i * sb->block_size))) != EOK)
+		    1, (ibmap_buf8 + i * sb->block_size))) != EOK)
 			return rc;
 	}
@@ -653,5 +667,5 @@
 	for (i = 0; i < zbmap_nblocks; ++i) {
 		if ((rc = write_block(start_block + i,
-				1, (zbmap_buf8 + i * sb->block_size))) != EOK)
+		    1, (zbmap_buf8 + i * sb->block_size))) != EOK)
 			return rc;
 	}
@@ -692,5 +706,6 @@
 		uint8_t *data_ptr = (uint8_t *) data;
 
-		rc = block_write_direct(service_id, tmp_off << 2, size << 2, data_ptr);
+		rc = block_write_direct(service_id, tmp_off << 2,
+		    size << 2, data_ptr);
 
 		if (rc != EOK)
@@ -700,7 +715,9 @@
 		tmp_off++;
 
-		return block_write_direct(service_id, tmp_off << 2, size << 2, data_ptr);
-	}
-	return block_write_direct(service_id, off << shift, size << shift, data);
+		return block_write_direct(service_id, tmp_off << 2,
+		    size << 2, data_ptr);
+	}
+	return block_write_direct(service_id, off << shift,
+	    size << shift, data);
 }
 
@@ -711,18 +728,27 @@
 	} else {
 		printf("Usage: [options] device\n"
-				"-1         Make a Minix version 1 filesystem\n"
-				"-2         Make a Minix version 2 filesystem\n"
-				"-b ##      Specify the block size in bytes (V3 only),\n"
-				"           valid block size values are 1024, 2048 and 4096 bytes per block\n"
-				"-i ##      Specify the number of inodes for the filesystem\n"
-				"-l         Use 30-char long filenames (V1/V2 only)\n");
-	}
-}
-
-static int num_of_set_bits(uint32_t n)
-{
-	n = n - ((n >> 1) & 0x55555555);
-	n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
-	return (((n + (n >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24;
+		    "-1         Make a Minix version 1 filesystem\n"
+		    "-2         Make a Minix version 2 filesystem\n"
+		    "-b ##      Specify the block size in bytes (V3 only),\n"
+		    "           valid block size values are 1024, 2048 and"
+				" 4096 bytes per block\n"
+		    "-i ##      Specify the number of inodes"
+				" for the filesystem\n"
+		    "-l         Use 30-char long filenames (V1/V2 only)\n");
+	}
+}
+
+/** Check if a given number is a power of two.
+ *
+ * @param n	The number to check.
+ *
+ * @return	true if it is a power of two, false otherwise.
+ */
+static bool is_power_of_two(uint32_t n)
+{
+	if (n == 0)
+		return false;
+
+	return (n & (n - 1)) == 0;
 }
 
