Index: uspace/srv/fs/minixfs/mfs_read.c
===================================================================
--- uspace/srv/fs/minixfs/mfs_read.c	(revision 930bacaa57eda20af53925e75553d6d3679e2296)
+++ uspace/srv/fs/minixfs/mfs_read.c	(revision 155f7929f70344ff1ca8c9122b07bc1948b77eab)
@@ -4,6 +4,5 @@
 #include "mfs_utils.h"
 
-static int read_map_v1(uint16_t *b, const struct mfs_node *mnode, int rblock);
-static int read_map_v2(uint32_t *b, const struct mfs_node *mnode, int rblock);
+static int read_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock);
 
 /*Given the position in the file expressed in
@@ -22,5 +21,4 @@
 	assert(sbi);
 
-	const mfs_version_t fs_version = sbi->fs_version;
 	const int block_size = sbi->block_size;
 
@@ -28,96 +26,25 @@
 	int rblock = pos / block_size;
 
-	if (fs_version == MFS_VERSION_V1) {
-		if (mnode->ino->i_size < (int32_t) pos)
-			return -1;
-
-		uint16_t b16 = 0;
-		r = read_map_v1(&b16, mnode, rblock);
-		*b = b16;
-	} else {
-		if (mnode->ino2->i_size < (int32_t) pos)
-			return -1;
-
-		r = read_map_v2(b, mnode, rblock);
-	}
-
-	return r;
-}
-
-static int read_map_v1(uint16_t *b, const struct mfs_node *mnode, int rblock)
-{
-	const int ptrs_per_block = MFS_BLOCKSIZE / sizeof(uint16_t);
-	block_t *bi1, *bi2;
-	const struct mfs_inode *ino = mnode->ino;
-	int r;
-
-	assert(ino);
-	assert(mnode->instance);
-
-	if (rblock < V1_NR_DIRECT_ZONES) {
-		*b = ino->i_dzone[rblock];
+	if (mnode->ino_i->i_size < (int32_t) pos) {
 		r = EOK;
+		*b = 0;
 		goto out;
 	}
 
-	rblock -= V1_NR_DIRECT_ZONES - 1;
-
-	/*Check if the wanted block is in the single indirect zone*/
-	if (rblock < ptrs_per_block) {
-		if (ino->i_izone[0] == 0) {
-			r = -1;
-			goto out;
-		}
-
-		r = read_ind_block(bi1, mnode->instance, ino->i_izone[0]);
-
-		if (r != EOK)
-			goto out;
-
-		*b = ((uint16_t *) bi1->data)[rblock];
-		goto out_block;
-	}
-
-	rblock -= ptrs_per_block - 1;
-
-	/*The wanted block is in the double indirect zone*/
-	uint16_t di_block = rblock / ptrs_per_block;
-
-	/*read the first indirect zone*/
-	if (ino->i_izone[1] == 0) {
-		r = -1;
-		goto out;
-	}
-
-	r = read_ind_block(bi1, mnode->instance, ino->i_izone[1]);
-
-	if (r != EOK)
-		goto out;
-
-	/*read the dobule indirect zone*/
-	r = read_ind_block(bi2, mnode->instance,
-			((uint16_t *) bi1->data)[di_block]);
-
-	if (r != EOK)
-		goto out_block;
-
-	*b = ((uint16_t *) bi2->data)[rblock % ptrs_per_block];
-	block_put(bi2);
-
-out_block:
-	block_put(bi1);
+	r = read_map_ondisk(b, mnode, rblock);
 out:
 	return r;
 }
 
-static int read_map_v2(uint32_t *b, const struct mfs_node *mnode, int rblock)
+static int read_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock)
 {
 	block_t *bi1, *bi2;
-	int r;
+	int r, nr_direct, nr_indirect;
+	int ptrs_per_block;
 
 	assert(mnode);
-	const struct mfs2_inode *ino2 = mnode->ino2;
+	const struct mfs_ino_info *ino_i = mnode->ino_i;
 
-	assert(ino2);
+	assert(ino_i);
 	assert(mnode->instance);
 
@@ -125,26 +52,38 @@
 	assert(sbi);
 
-	const int ptrs_per_block = sbi->block_size / sizeof(uint32_t);
+	const int fs_version = sbi->fs_version;
 
-	if (rblock < V2_NR_DIRECT_ZONES) {
-		*b = ino2->i_dzone[rblock];
+	if (fs_version == MFS_VERSION_V1) {
+		nr_direct = V1_NR_DIRECT_ZONES;
+		nr_indirect = V1_NR_INDIRECT_ZONES;
+		ptrs_per_block = MFS_BLOCKSIZE / sizeof(uint16_t);
+	} else {
+		nr_direct = V2_NR_DIRECT_ZONES;
+		nr_indirect = V2_NR_INDIRECT_ZONES;
+		ptrs_per_block = sbi->block_size / sizeof(uint32_t);
+	}
+
+	if (rblock < nr_direct) {
+		*b = ino_i->i_dzone[rblock];
 		r = EOK;
 		goto out;
 	}
-	rblock -= V2_NR_DIRECT_ZONES - 1;
+	rblock -= nr_direct - 1;
 
 	/*Check if the wanted block is in the single indirect zone*/
 	if (rblock < ptrs_per_block) {
-		if (ino2->i_izone[0] == 0) {
+		if (ino_i->i_izone[0] == 0) {
 			r = -1;
 			goto out;
 		}
 
-		r = read_ind_block(bi2, mnode->instance, ino2->i_izone[0]);
+		r = read_ind_block(bi2, mnode->instance, ino_i->i_izone[0]);
 
 		if (r != EOK)
 			goto out;
 
-		*b = ((uint32_t *) bi1->data)[rblock];
+		*b = fs_version == MFS_VERSION_V1 ? 
+				((uint16_t *) bi1->data)[rblock] :
+				((uint32_t *) bi1->data)[rblock];
 		goto out_block;
 	}
@@ -156,10 +95,10 @@
 
 	/*read the first indirect zone*/
-	if (ino2->i_izone[1] == 0) {
+	if (ino_i->i_izone[1] == 0) {
 		r = -1;
 		goto out;
 	}
 
-	r = read_ind_block(bi1, mnode->instance, ino2->i_izone[1]);
+	r = read_ind_block(bi1, mnode->instance, ino_i->i_izone[1]);
 
 	if (r != EOK)
@@ -167,11 +106,21 @@
 
 	/*read the second indirect zone*/
-	r = read_ind_block(bi2, mnode->instance,
+	if (fs_version == MFS_VERSION_V1) {
+		r = read_ind_block(bi2, mnode->instance,
+			((uint16_t *) bi1->data)[di_block]);
+
+		if (r != EOK)
+			goto out_block;
+
+		*b = ((uint16_t *) bi2->data)[rblock % ptrs_per_block];
+	} else {
+		r = read_ind_block(bi2, mnode->instance,
 			((uint32_t *) bi1->data)[di_block]);
 
-	if (r != EOK)
-		goto out_block;
+		if (r != EOK)
+			goto out_block;
 
-	*b = ((uint32_t *) bi2->data)[rblock % ptrs_per_block];
+		*b = ((uint32_t *) bi2->data)[rblock % ptrs_per_block];
+	}
 	block_put(bi2);
 
