Index: uspace/srv/fs/mfs/mfs.c
===================================================================
--- uspace/srv/fs/mfs/mfs.c	(revision 03f4acf5654704475729ead26a4f10b913366ead)
+++ uspace/srv/fs/mfs/mfs.c	(revision 9dd79bc772aec18ce4a7944d47ff90f38da9e6bb)
@@ -74,5 +74,5 @@
 
 	async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
-				SERVICE_VFS, 0, 0);
+	    SERVICE_VFS, 0, 0);
 
 	if (!vfs_sess) {
Index: uspace/srv/fs/mfs/mfs_balloc.c
===================================================================
--- uspace/srv/fs/mfs/mfs_balloc.c	(revision 03f4acf5654704475729ead26a4f10b913366ead)
+++ uspace/srv/fs/mfs/mfs_balloc.c	(revision 9dd79bc772aec18ce4a7944d47ff90f38da9e6bb)
@@ -36,5 +36,5 @@
 static int
 find_free_bit_and_set(bitchunk_t *b, const int bsize,
-		      const bool native, unsigned start_bit);
+    const bool native, unsigned start_bit);
 
 static int
@@ -129,19 +129,19 @@
 		if (idx > sbi->nzones) {
 			printf(NAME ": Error! Trying to free beyond the" \
-			       "bitmap max size\n");
+			    "bitmap max size\n");
 			return -1;
 		}
 	} else {
-		/*bid == BMAP_INODE*/
+		/* bid == BMAP_INODE */
 		search = &sbi->isearch;
 		start_block = 2;
 		if (idx > sbi->ninodes) {
 			printf(NAME ": Error! Trying to free beyond the" \
-			       "bitmap max size\n");
+			    "bitmap max size\n");
 			return -1;
 		}
 	}
 
-	/*Compute the bitmap block*/
+	/* Compute the bitmap block */
 	uint32_t block = idx / (sbi->block_size * 8) + start_block;
 
@@ -150,5 +150,5 @@
 		goto out_err;
 
-	/*Compute the bit index in the block*/
+	/* Compute the bit index in the block */
 	idx %= (sbi->block_size * 8);
 	bitchunk_t *ptr = b->data;
@@ -220,7 +220,7 @@
 
 		freebit = find_free_bit_and_set(b->data, sbi->block_size,
-						sbi->native, tmp);
+		    sbi->native, tmp);
 		if (freebit == -1) {
-			/*No free bit in this block*/
+			/* No free bit in this block */
 			r = block_put(b);
 			if (r != EOK)
@@ -229,8 +229,8 @@
 		}
 
-		/*Free bit found in this block, compute the real index*/
+		/* Free bit found in this block, compute the real index */
 		*idx = freebit + bits_per_block * i;
 		if (*idx > limit) {
-			/*Index is beyond the limit, it is invalid*/
+			/* Index is beyond the limit, it is invalid */
 			r = block_put(b);
 			if (r != EOK)
@@ -246,10 +246,10 @@
 
 	if (*search > 0) {
-		/*Repeat the search from the first bitmap block*/
+		/* Repeat the search from the first bitmap block */
 		*search = 0;
 		goto retry;
 	}
 
-	/*Free bit not found, return error*/
+	/* Free bit not found, return error */
 	return ENOSPC;
 
@@ -260,5 +260,5 @@
 static int
 find_free_bit_and_set(bitchunk_t *b, const int bsize,
-		      const bool native, unsigned start_bit)
+    const bool native, unsigned start_bit)
 {
 	int r = -1;
@@ -268,7 +268,8 @@
 
 	for (i = start_bit / chunk_bits;
-	     i < bsize / sizeof(bitchunk_t); ++i) {
+	    i < bsize / sizeof(bitchunk_t); ++i) {
+
 		if (!(~b[i])) {
-			/*No free bit in this chunk*/
+			/* No free bit in this chunk */
 			continue;
 		}
Index: uspace/srv/fs/mfs/mfs_dentry.c
===================================================================
--- uspace/srv/fs/mfs/mfs_dentry.c	(revision 03f4acf5654704475729ead26a4f10b913366ead)
+++ uspace/srv/fs/mfs/mfs_dentry.c	(revision 9dd79bc772aec18ce4a7944d47ff90f38da9e6bb)
@@ -44,5 +44,5 @@
 int
 mfs_read_dentry(struct mfs_node *mnode,
-		     struct mfs_dentry_info *d_info, unsigned index)
+    struct mfs_dentry_info *d_info, unsigned index)
 {
 	const struct mfs_instance *inst = mnode->instance;
@@ -57,5 +57,5 @@
 
 	if (block == 0) {
-		/*End of the dentries list*/
+		/* End of the dentries list */
 		r = EOK;
 		goto out_err;
@@ -79,10 +79,10 @@
 	} else {
 		const int namelen = longnames ? MFS_L_MAX_NAME_LEN :
-				    MFS_MAX_NAME_LEN;
+		    MFS_MAX_NAME_LEN;
 
 		struct mfs_dentry *d;
 
 		d = b->data + dentry_off * (longnames ? MFSL_DIRSIZE :
-					    MFS_DIRSIZE);
+		    MFS_DIRSIZE);
 		d_info->d_inum = conv16(sbi->native, d->d_inum);
 		memcpy(d_info->d_name, d->d_name, namelen);
@@ -101,7 +101,7 @@
 /**Write a directory entry on disk.
  *
- * @param d_info	Pointer to the directory entry structure to write on disk.
- *
- * @return		EOK on success or a negative error code.
+ * @param d_info Pointer to the directory entry structure to write on disk.
+ *
+ * @return	 EOK on success or a negative error code.
  */
 int
@@ -178,5 +178,6 @@
 
 		if (name_len == d_name_len &&
-				!bcmp(d_info.d_name, d_name, name_len)) {
+		    !bcmp(d_info.d_name, d_name, name_len)) {
+
 			d_info.d_inum = 0;
 			r = mfs_write_dentry(&d_info);
@@ -197,5 +198,6 @@
  */
 int
-mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum)
+mfs_insert_dentry(struct mfs_node *mnode, const char *d_name,
+    fs_index_t d_inum)
 {
 	int r;
@@ -209,5 +211,5 @@
 		return ENAMETOOLONG;
 
-	/*Search for an empty dentry*/
+	/* Search for an empty dentry */
 	unsigned i;
 	for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
@@ -217,5 +219,5 @@
 
 		if (d_info.d_inum == 0) {
-			/*This entry is not used*/
+			/* This entry is not used */
 			empty_dentry_found = true;
 			break;
@@ -231,5 +233,5 @@
 
 		if (b == 0) {
-			/*Increase the inode size*/
+			/* Increase the inode size */
 
 			uint32_t dummy;
Index: uspace/srv/fs/mfs/mfs_inode.c
===================================================================
--- uspace/srv/fs/mfs/mfs_inode.c	(revision 03f4acf5654704475729ead26a4f10b913366ead)
+++ uspace/srv/fs/mfs/mfs_inode.c	(revision 9dd79bc772aec18ce4a7944d47ff90f38da9e6bb)
@@ -42,9 +42,9 @@
 static int
 mfs_read_inode_raw(const struct mfs_instance *instance,
-		struct mfs_ino_info **ino_ptr, uint16_t inum);
+    struct mfs_ino_info **ino_ptr, uint16_t inum);
 
 static int
 mfs2_read_inode_raw(const struct mfs_instance *instance,
-		struct mfs_ino_info **ino_ptr, uint32_t inum);
+    struct mfs_ino_info **ino_ptr, uint32_t inum);
 
 /**Read a MINIX inode from disk
@@ -59,5 +59,5 @@
 int
 mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
-	  fs_index_t index)
+    fs_index_t index)
 {
 	struct mfs_sb_info *sbi = inst->sbi;
@@ -65,8 +65,8 @@
 
 	if (sbi->fs_version == MFS_VERSION_V1) {
-		/*Read a MFS V1 inode*/
+		/* Read a MFS V1 inode */
 		r = mfs_read_inode_raw(inst, ino_i, index);
 	} else {
-		/*Read a MFS V2/V3 inode*/
+		/* Read a MFS V2/V3 inode */
 		r = mfs2_read_inode_raw(inst, ino_i, index);
 	}
@@ -77,5 +77,6 @@
 static int
 mfs_read_inode_raw(const struct mfs_instance *instance,
-		struct mfs_ino_info **ino_ptr, uint16_t inum) {
+    struct mfs_ino_info **ino_ptr, uint16_t inum)
+{
 	struct mfs_inode *ino;
 	struct mfs_ino_info *ino_i = NULL;
@@ -86,5 +87,5 @@
 	sbi = instance->sbi;
 
-	/*inode 0 does not exist*/
+	/* inode 0 does not exist */
 	inum -= 1;
 
@@ -101,6 +102,7 @@
 
 	r = block_get(&b, instance->service_id,
-		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE);
+	    itable_off + inum / sbi->ino_per_block,
+	    BLOCK_FLAGS_NONE);
+
 	if (r != EOK)
 		goto out_err;
@@ -134,5 +136,6 @@
 static int
 mfs2_read_inode_raw(const struct mfs_instance *instance,
-		struct mfs_ino_info **ino_ptr, uint32_t inum) {
+    struct mfs_ino_info **ino_ptr, uint32_t inum)
+{
 	struct mfs2_inode *ino;
 	struct mfs_ino_info *ino_i = NULL;
@@ -150,5 +153,5 @@
 	sbi = instance->sbi;
 
-	/*inode 0 does not exist*/
+	/* inode 0 does not exist */
 	inum -= 1;
 
@@ -157,6 +160,7 @@
 
 	r = block_get(&b, instance->service_id,
-		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE);
+	    itable_off + inum / sbi->ino_per_block,
+	    BLOCK_FLAGS_NONE);
+
 	if (r != EOK)
 		goto out_err;
@@ -322,5 +326,5 @@
 
 	if (size_shrink == 0) {
-		/*File is empty*/
+		/* Nothing to be done */
 		return EOK;
 	}
@@ -333,5 +337,5 @@
 	ino_i->dirty = true;
 
-	/*Compute the number of zones to free*/
+	/* Compute the number of zones to free */
 	unsigned zones_to_free;
 
@@ -354,5 +358,5 @@
 
 		if (old_zone == 0)
-			continue; /*Sparse block*/
+			continue; /* Sparse block */
 
 		r = mfs_free_zone(mnode->instance, old_zone);
Index: uspace/srv/fs/mfs/mfs_ops.c
===================================================================
--- uspace/srv/fs/mfs/mfs_ops.c	(revision 03f4acf5654704475729ead26a4f10b913366ead)
+++ uspace/srv/fs/mfs/mfs_ops.c	(revision 9dd79bc772aec18ce4a7944d47ff90f38da9e6bb)
@@ -43,8 +43,7 @@
 
 static bool check_magic_number(uint16_t magic, bool *native,
-			       mfs_version_t *version, bool *longfilenames);
+    mfs_version_t *version, bool *longfilenames);
 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
-			     fs_index_t index);
-
+    fs_index_t index);
 static int mfs_node_put(fs_node_t *fsnode);
 static int mfs_node_open(fs_node_t *fsnode);
@@ -64,12 +63,12 @@
 static hash_index_t open_nodes_hash(unsigned long key[]);
 static int open_nodes_compare(unsigned long key[], hash_count_t keys,
-		link_t *item);
+    link_t *item);
 static void open_nodes_remove_cb(link_t *link);
-
 static int mfs_node_get(fs_node_t **rfn, service_id_t service_id,
-			fs_index_t index);
-static int
-mfs_instance_get(service_id_t service_id, struct mfs_instance **instance);
-
+    fs_index_t index);
+static int mfs_instance_get(service_id_t service_id,
+    struct mfs_instance **instance);
+static int mfs_check_sanity(struct mfs_sb_info *sbi);
+static bool is_power_of_two(uint32_t n);
 
 static hash_table_t open_nodes;
@@ -96,5 +95,6 @@
 
 /* Hash table interface for open nodes hash table */
-static hash_index_t open_nodes_hash(unsigned long key[])
+static hash_index_t
+open_nodes_hash(unsigned long key[])
 {
 	/* TODO: This is very simple and probably can be improved */
@@ -102,6 +102,7 @@
 }
 
-static int open_nodes_compare(unsigned long key[], hash_count_t keys,
-		link_t *item)
+static int
+open_nodes_compare(unsigned long key[], hash_count_t keys,
+    link_t *item)
 {
 	struct mfs_node *mnode = hash_table_get_instance(item, struct mfs_node, link);
@@ -118,5 +119,6 @@
 }
 
-static void open_nodes_remove_cb(link_t *link)
+static void
+open_nodes_remove_cb(link_t *link)
 {
 	/* We don't use remove callback for this hash table */
@@ -129,8 +131,9 @@
 };
 
-int mfs_global_init(void)
+int
+mfs_global_init(void)
 {
 	if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS,
-			OPEN_NODES_KEYS, &open_nodes_ops)) {
+	    OPEN_NODES_KEYS, &open_nodes_ops)) {
 		return ENOMEM;
 	}
@@ -140,5 +143,5 @@
 static int
 mfs_mounted(service_id_t service_id, const char *opts, fs_index_t *index,
-		aoff64_t *size, unsigned *linkcnt)
+    aoff64_t *size, unsigned *linkcnt)
 {
 	enum cache_mode cmode;
@@ -163,5 +166,5 @@
 		return rc;
 
-	/*Allocate space for generic MFS superblock*/
+	/* Allocate space for generic MFS superblock */
 	sbi = malloc(sizeof(*sbi));
 	if (!sbi) {
@@ -170,5 +173,5 @@
 	}
 
-	/*Allocate space for filesystem instance*/
+	/* Allocate space for filesystem instance */
 	instance = malloc(sizeof(*instance));
 	if (!instance) {
@@ -191,11 +194,11 @@
 
 	if (check_magic_number(sb->s_magic, &native, &version, &longnames)) {
-		/*This is a V1 or V2 Minix filesystem*/
+		/* This is a V1 or V2 Minix filesystem */
 		magic = sb->s_magic;
 	} else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) {
-		/*This is a V3 Minix filesystem*/
+		/* This is a V3 Minix filesystem */
 		magic = sb3->s_magic;
 	} else {
-		/*Not recognized*/
+		/* Not recognized */
 		mfsdebug("magic number not recognized\n");
 		rc = ENOTSUP;
@@ -205,5 +208,5 @@
 	mfsdebug("magic number recognized = %04x\n", magic);
 
-	/*Fill superblock info structure*/
+	/* Fill superblock info structure */
 
 	sbi->fs_version = version;
@@ -243,5 +246,5 @@
 		sbi->dirsize = longnames ? MFSL_DIRSIZE : MFS_DIRSIZE;
 		sbi->max_name_len = longnames ? MFS_L_MAX_NAME_LEN :
-				    MFS_MAX_NAME_LEN;
+		    MFS_MAX_NAME_LEN;
 	}
 
@@ -259,4 +262,8 @@
 
 	sbi->itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks;
+	if ((rc = mfs_check_sanity(sbi)) != EOK) {
+		fprintf(stderr, "Filesystem corrupted, invalid superblock");
+		goto out_error;
+	}
 
 	rc = block_cache_init(service_id, sbi->block_size, 0, cmode);
@@ -267,5 +274,5 @@
 	}
 
-	/*Initialize the instance structure and remember it*/
+	/* Initialize the instance structure and remember it */
 	instance->service_id = service_id;
 	instance->sbi = sbi;
@@ -273,10 +280,7 @@
 	rc = fs_instance_create(service_id, instance);
 	if (rc != EOK) {
-		free(instance);
-		free(sbi);
 		block_cache_fini(service_id);
-		block_fini(service_id);
 		mfsdebug("fs instance creation failed\n");
-		return rc;
+		goto out_error;
 	}
 
@@ -331,5 +335,6 @@
 }
 
-service_id_t mfs_service_get(fs_node_t *fsnode)
+service_id_t
+mfs_service_get(fs_node_t *fsnode)
 {
 	struct mfs_node *node = fsnode->data;
@@ -337,5 +342,6 @@
 }
 
-static int mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
+static int
+mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
 {
 	int r;
@@ -351,5 +357,5 @@
 		return r;
 
-	/*Alloc a new inode*/
+	/* Alloc a new inode */
 	r = mfs_alloc_inode(inst, &inum);
 	if (r != EOK)
@@ -378,5 +384,5 @@
 	if (flags & L_DIRECTORY) {
 		ino_i->i_mode = S_IFDIR;
-		ino_i->i_nlinks = 2; /*This accounts for the '.' dentry*/
+		ino_i->i_nlinks = 2; /* This accounts for the '.' dentry */
 	} else {
 		ino_i->i_mode = S_IFREG;
@@ -431,5 +437,6 @@
 }
 
-static int mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
+static int
+mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
 {
 	struct mfs_node *mnode = pfn->data;
@@ -453,5 +460,5 @@
 
 		if (!d_info.d_inum) {
-			/*This entry is not used*/
+			/* This entry is not used */
 			continue;
 		}
@@ -460,8 +467,8 @@
 
 		if (comp_size == dentry_name_size &&
-			!bcmp(component, d_info.d_name, dentry_name_size)) {
-			/*Hit!*/
+		    !bcmp(component, d_info.d_name, dentry_name_size)) {
+			/* Hit! */
 			mfs_node_core_get(rfn, mnode->instance,
-					  d_info.d_inum);
+			    d_info.d_inum);
 			goto found;
 		}
@@ -472,5 +479,6 @@
 }
 
-static aoff64_t mfs_size_get(fs_node_t *node)
+static aoff64_t
+mfs_size_get(fs_node_t *node)
 {
 	const struct mfs_node *mnode = node->data;
@@ -480,5 +488,5 @@
 static int
 mfs_node_get(fs_node_t **rfn, service_id_t service_id,
-			fs_index_t index)
+    fs_index_t index)
 {
 	int rc;
@@ -524,5 +532,6 @@
 }
 
-static int mfs_node_open(fs_node_t *fsnode)
+static int
+mfs_node_open(fs_node_t *fsnode)
 {
 	/*
@@ -533,5 +542,6 @@
 }
 
-static fs_index_t mfs_index_get(fs_node_t *fsnode)
+static fs_index_t
+mfs_index_get(fs_node_t *fsnode)
 {
 	struct mfs_node *mnode = fsnode->data;
@@ -539,5 +549,6 @@
 }
 
-static unsigned mfs_lnkcnt_get(fs_node_t *fsnode)
+static unsigned
+mfs_lnkcnt_get(fs_node_t *fsnode)
 {
 	struct mfs_node *mnode = fsnode->data;
@@ -554,6 +565,7 @@
 }
 
-static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
-			     fs_index_t index)
+static int
+mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
+    fs_index_t index)
 {
 	fs_node_t *node = NULL;
@@ -627,5 +639,6 @@
 }
 
-static bool mfs_is_directory(fs_node_t *fsnode)
+static bool
+mfs_is_directory(fs_node_t *fsnode)
 {
 	const struct mfs_node *node = fsnode->data;
@@ -633,5 +646,6 @@
 }
 
-static bool mfs_is_file(fs_node_t *fsnode)
+static bool
+mfs_is_file(fs_node_t *fsnode)
 {
 	struct mfs_node *node = fsnode->data;
@@ -639,5 +653,6 @@
 }
 
-static int mfs_root_get(fs_node_t **rfn, service_id_t service_id)
+static int
+mfs_root_get(fs_node_t **rfn, service_id_t service_id)
 {
 	int rc = mfs_node_get(rfn, service_id, MFS_ROOT_INO);
@@ -645,5 +660,6 @@
 }
 
-static int mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
+static int
+mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
 {
 	struct mfs_node *parent = pfn->data;
@@ -720,5 +736,6 @@
 }
 
-static int mfs_has_children(bool *has_children, fs_node_t *fsnode)
+static int
+mfs_has_children(bool *has_children, fs_node_t *fsnode)
 {
 	struct mfs_node *mnode = fsnode->data;
@@ -741,5 +758,5 @@
 
 		if (d_info.d_inum) {
-			/*A valid entry has been found*/
+			/* A valid entry has been found */
 			*has_children = true;
 			break;
@@ -753,5 +770,5 @@
 static int
 mfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos,
-		size_t *rbytes)
+    size_t *rbytes)
 {
 	int rc;
@@ -783,5 +800,5 @@
 
 		if (pos < 2) {
-			/*Skip the first two dentries ('.' and '..')*/
+			/* Skip the first two dentries ('.' and '..') */
 			pos = 2;
 		}
@@ -793,5 +810,5 @@
 
 			if (d_info.d_inum) {
-				/*Dentry found!*/
+				/* Dentry found! */
 				goto found;
 			}
@@ -809,5 +826,5 @@
 
 		if (pos >= (size_t) ino_i->i_size) {
-			/*Trying to read beyond the end of file*/
+			/* Trying to read beyond the end of file */
 			bytes = 0;
 			(void) async_data_read_finalize(callid, NULL, 0);
@@ -826,5 +843,5 @@
 
 		if (zone == 0) {
-			/*sparse file*/
+			/* sparse file */
 			uint8_t *buf = malloc(sbi->block_size);
 			if (!buf) {
@@ -834,5 +851,5 @@
 			memset(buf, 0, sizeof(sbi->block_size));
 			async_data_read_finalize(callid,
-						 buf + pos % sbi->block_size, bytes);
+			    buf + pos % sbi->block_size, bytes);
 			free(buf);
 			goto out_success;
@@ -844,5 +861,5 @@
 
 		async_data_read_finalize(callid, b->data +
-					 pos % sbi->block_size, bytes);
+		    pos % sbi->block_size, bytes);
 
 		rc = block_put(b);
@@ -865,5 +882,5 @@
 static int
 mfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos,
-		size_t *wbytes, aoff64_t *nsize)
+    size_t *wbytes, aoff64_t *nsize)
 {
 	fs_node_t *fn;
@@ -900,5 +917,4 @@
 
 	if (block == 0) {
-		/*Writing in a sparse block*/
 		uint32_t dummy;
 
@@ -958,5 +974,5 @@
 		return ENOENT;
 
-	/*Destroy the inode*/
+	/* Destroy the inode */
 	return mfs_destroy_node(fn);
 }
@@ -977,10 +993,10 @@
 	assert(!has_children);
 
-	/*Free the entire inode content*/
+	/* Free the entire inode content */
 	r = mfs_inode_shrink(mnode, mnode->ino_i->i_size);
 	if (r != EOK)
 		goto out;
 
-	/*Mark the inode as free in the bitmap*/
+	/* Mark the inode as free in the bitmap */
 	r = mfs_free_inode(mnode->instance, mnode->ino_i->index);
 
@@ -1021,7 +1037,7 @@
 
 	rc = fs_instance_get(service_id, &data);
-	if (rc == EOK) {
+	if (rc == EOK)
 		*instance = (struct mfs_instance *) data;
-	} else {
+	else {
 		mfsdebug("instance not found\n");
 	}
@@ -1030,6 +1046,7 @@
 }
 
-static bool check_magic_number(uint16_t magic, bool *native,
-			       mfs_version_t *version, bool *longfilenames)
+static bool
+check_magic_number(uint16_t magic, bool *native,
+		mfs_version_t *version, bool *longfilenames)
 {
 	bool rc = true;
@@ -1059,4 +1076,27 @@
 }
 
+/** Filesystem sanity check
+ *
+ * @param Pointer to the MFS superblock.
+ *
+ * @return EOK on success, ENOTSUP otherwise.
+ */
+static int
+mfs_check_sanity(struct mfs_sb_info *sbi)
+{
+	if (!is_power_of_two(sbi->block_size) ||
+	    sbi->block_size < MFS_MIN_BLOCKSIZE ||
+	    sbi->block_size > MFS_MAX_BLOCKSIZE)
+		return ENOTSUP;
+	else if (sbi->ibmap_blocks == 0 || sbi->zbmap_blocks == 0)
+		return ENOTSUP;
+	else if (sbi->ninodes == 0 || sbi->nzones == 0)
+		return ENOTSUP;
+	else if (sbi->firstdatazone == 0)
+		return ENOTSUP;
+
+	return EOK;
+}
+
 static int
 mfs_close(service_id_t service_id, fs_index_t index)
@@ -1079,4 +1119,19 @@
 
 	return mfs_node_put(fn);
+}
+
+/** 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;
 }
 
Index: uspace/srv/fs/mfs/mfs_rw.c
===================================================================
--- uspace/srv/fs/mfs/mfs_rw.c	(revision 03f4acf5654704475729ead26a4f10b913366ead)
+++ uspace/srv/fs/mfs/mfs_rw.c	(revision 9dd79bc772aec18ce4a7944d47ff90f38da9e6bb)
@@ -36,5 +36,5 @@
 static int
 rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
-	      bool write_mode, uint32_t w_block);
+    bool write_mode, uint32_t w_block);
 
 static int
@@ -68,9 +68,9 @@
 	const int block_size = sbi->block_size;
 
-	/*Compute relative block number in file*/
+	/* Compute relative block number in file */
 	int rblock = pos / block_size;
 
 	if (ROUND_UP(mnode->ino_i->i_size, sbi->block_size) < pos) {
-		/*Trying to read beyond the end of file*/
+		/* Trying to read beyond the end of file */
 		r = EOK;
 		*b = 0;
@@ -85,14 +85,14 @@
 int
 mfs_write_map(struct mfs_node *mnode, const uint32_t pos, uint32_t new_zone,
-	  uint32_t *old_zone)
+    uint32_t *old_zone)
 {
 	const struct mfs_sb_info *sbi = mnode->instance->sbi;
 
 	if (pos >= sbi->max_file_size) {
-		/*Can't write beyond the maximum file size*/
+		/* Can't write beyond the maximum file size */
 		return EINVAL;
 	}
 
-	/*Compute the relative block number in file*/
+	/* Compute the relative block number in file */
 	int rblock = pos / sbi->block_size;
 
@@ -102,5 +102,5 @@
 static int
 rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
-	      bool write_mode, uint32_t w_block)
+    bool write_mode, uint32_t w_block)
 {
 	int r, nr_direct;
@@ -123,5 +123,5 @@
 	}
 
-	/*Check if the wanted block is in the direct zones*/
+	/* Check if the wanted block is in the direct zones */
 	if (rblock < nr_direct) {
 		*b = ino_i->i_dzone[rblock];
@@ -136,5 +136,5 @@
 
 	if (rblock < ptrs_per_block) {
-		/*The wanted block is in the single indirect zone chain*/
+		/* The wanted block is in the single indirect zone chain */
 		if (ino_i->i_izone[0] == 0) {
 			if (write_mode && !deleting) {
@@ -168,7 +168,7 @@
 	rblock -= ptrs_per_block;
 
-	/*The wanted block is in the double indirect zone chain*/
-
-	/*read the first indirect zone of the chain*/
+	/* The wanted block is in the double indirect zone chain */
+
+	/* Read the first indirect zone of the chain */
 	if (ino_i->i_izone[1] == 0) {
 		if (write_mode && !deleting) {
@@ -181,5 +181,5 @@
 			ino_i->dirty = true;
 		} else {
-			/*Sparse block*/
+			/* Sparse block */
 			*b = 0;
 			return EOK;
@@ -192,10 +192,10 @@
 
 	/*
-	 *Compute the position of the second indirect
-	 *zone pointer in the chain.
+	 * Compute the position of the second indirect
+	 * zone pointer in the chain.
 	 */
 	uint32_t ind2_off = rblock / ptrs_per_block;
 
-	/*read the second indirect zone of the chain*/
+	/* read the second indirect zone of the chain */
 	if (ind_zone[ind2_off] == 0) {
 		if (write_mode && !deleting) {
@@ -208,5 +208,5 @@
 			write_ind_zone(inst, ino_i->i_izone[1], ind_zone);
 		} else {
-			/*Sparse block*/
+			/* Sparse block */
 			r = EOK;
 			*b = 0;
@@ -264,5 +264,5 @@
 
 	if (rblock < nr_direct) {
-		/*free the single indirect zone*/
+		/* Free the single indirect zone */
 		if (ino_i->i_izone[0]) {
 			r = mfs_free_zone(inst, ino_i->i_izone[0]);
@@ -282,9 +282,9 @@
 		++fzone_to_free;
 
-	/*free the entire double indirect zone*/
+	/* Free the entire double indirect zone */
 	uint32_t *dbl_zone;
 
 	if (ino_i->i_izone[1] == 0) {
-		/*Nothing to be done*/
+		/* Nothing to be done */
 		return EOK;
 	}
@@ -350,5 +350,5 @@
 	block_t *b;
 	const int max_ind_zone_ptrs = (MFS_MAX_BLOCKSIZE / sizeof(uint16_t)) *
-				      sizeof(uint32_t);
+	    sizeof(uint32_t);
 
 	*ind_zone = malloc(max_ind_zone_ptrs);
Index: uspace/srv/fs/mfs/mfs_utils.c
===================================================================
--- uspace/srv/fs/mfs/mfs_utils.c	(revision 03f4acf5654704475729ead26a4f10b913366ead)
+++ uspace/srv/fs/mfs/mfs_utils.c	(revision 9dd79bc772aec18ce4a7944d47ff90f38da9e6bb)
@@ -34,5 +34,6 @@
 #include "mfs.h"
 
-uint16_t conv16(bool native, uint16_t n)
+uint16_t
+conv16(bool native, uint16_t n)
 {
 	if (native)
@@ -42,5 +43,6 @@
 }
 
-uint32_t conv32(bool native, uint32_t n)
+uint32_t
+conv32(bool native, uint32_t n)
 {
 	if (native)
@@ -50,5 +52,6 @@
 }
 
-uint64_t conv64(bool native, uint64_t n)
+uint64_t
+conv64(bool native, uint64_t n)
 {
 	if (native)
