Index: uspace/srv/fs/minixfs/mfs_inode.c
===================================================================
--- uspace/srv/fs/minixfs/mfs_inode.c	(revision b2a1823405b6aa37267ff487997d3786b597a6bd)
+++ uspace/srv/fs/minixfs/mfs_inode.c	(revision 4bf0052a79f6b1f9b3c6429b7ee290154848778b)
@@ -40,9 +40,11 @@
 mfs2_write_inode_raw(struct mfs_node *mnode);
 
-static struct mfs_ino_info *
-mfs_read_inode_raw(const struct mfs_instance *instance, uint16_t inum);
-
-static struct mfs_ino_info *
-mfs2_read_inode_raw(const struct mfs_instance *instance, uint32_t inum);
+static int
+mfs_read_inode_raw(const struct mfs_instance *instance,
+		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);
 
 
@@ -52,26 +54,25 @@
 {
 	struct mfs_sb_info *sbi = inst->sbi;
+	int r;
 
 	if (sbi->fs_version == MFS_VERSION_V1) {
 		/*Read a MFS V1 inode*/
-		*ino_i = mfs_read_inode_raw(inst, index);
+		r = mfs_read_inode_raw(inst, ino_i, index);
 	} else {
 		/*Read a MFS V2/V3 inode*/
-		*ino_i = mfs2_read_inode_raw(inst, index);
-	}
-
-	if (*ino_i == NULL)
-		return -1;
-
-	return EOK;
-}
-
-static struct mfs_ino_info *
-mfs_read_inode_raw(const struct mfs_instance *instance, uint16_t inum) {
-	struct mfs_inode *ino = NULL;
+		r = mfs2_read_inode_raw(inst, ino_i, index);
+	}
+
+	return r;
+}
+
+static int
+mfs_read_inode_raw(const struct mfs_instance *instance,
+		struct mfs_ino_info **ino_ptr, uint16_t inum) {
+	struct mfs_inode *ino;
 	struct mfs_ino_info *ino_i = NULL;
 	struct mfs_sb_info *sbi;
 	block_t *b;
-	int i;
+	int i, r;
 
 	sbi = instance->sbi;
@@ -82,20 +83,20 @@
 
 	const int ino_off = inum % sbi->ino_per_block;
-	const size_t ino_size = sizeof(struct mfs_inode);
 
 	ino_i = malloc(sizeof(*ino_i));
-	ino = malloc(ino_size);
-
-	if (!ino || !ino_i)
+
+	if (!ino_i) {
+		r = ENOMEM;
 		goto out_err;
+	}
 
 	const int itable_off = sbi->itable_off;
 
-	if (block_get(&b, instance->handle,
+	r = block_get(&b, instance->handle,
 		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE) != EOK)
-		goto out_err;
-
-	memcpy(ino, ((uint8_t *) b->data) + ino_off * ino_size, ino_size);
+		      BLOCK_FLAGS_NONE);
+	on_error(r, goto out_err);
+
+	ino = b->data + ino_off * sizeof(struct mfs_inode);
 
 	ino_i->i_mode = conv16(sbi->native, ino->i_mode);
@@ -111,33 +112,31 @@
 		ino_i->i_izone[i] = conv16(sbi->native, ino->i_izone[i]);
 
-	block_put(b);
-	free(ino);
+	r = block_put(b);
 	ino_i->dirty = false;
-
-	return ino_i;
+	*ino_ptr = ino_i;
+
+	return r;
 
 out_err:
-	if (ino)
-		free(ino);
 	if (ino_i)
 		free(ino_i);
-	return NULL;
-}
-
-static struct mfs_ino_info *
-mfs2_read_inode_raw(const struct mfs_instance *instance, uint32_t inum) {
-	struct mfs2_inode *ino = NULL;
+	return EOK;
+}
+
+static int
+mfs2_read_inode_raw(const struct mfs_instance *instance,
+		struct mfs_ino_info **ino_ptr, uint32_t inum) {
+	struct mfs2_inode *ino;
 	struct mfs_ino_info *ino_i = NULL;
 	struct mfs_sb_info *sbi;
 	block_t *b;
-	int i;
-
-	const size_t ino_size = sizeof(struct mfs2_inode);
-
-	ino = malloc(ino_size);
+	int i, r;
+
 	ino_i = malloc(sizeof(*ino_i));
 
-	if (!ino || !ino_i)
+	if (!ino_i) {
+		r = ENOMEM;
 		goto out_err;
+	}
 
 	sbi = instance->sbi;
@@ -150,10 +149,10 @@
 	const int ino_off = inum % sbi->ino_per_block;
 
-	if (block_get(&b, instance->handle,
+	r = block_get(&b, instance->handle,
 		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE) != EOK)
-		goto out_err;
-
-	memcpy(ino, b->data + ino_off * ino_size, ino_size);
+		      BLOCK_FLAGS_NONE);
+	on_error(r, goto out_err);
+
+	ino = b->data + ino_off * sizeof(struct mfs2_inode);
 
 	ino_i->i_mode = conv16(sbi->native, ino->i_mode);
@@ -172,16 +171,14 @@
 		ino_i->i_izone[i] = conv32(sbi->native, ino->i_izone[i]);
 
-	block_put(b);
-	free(ino);
+	r = block_put(b);
 	ino_i->dirty = false;
-
-	return ino_i;
+	*ino_ptr = ino_i;
+
+	return r;
 
 out_err:
-	if (ino)
-		free(ino);
 	if (ino_i)
 		free(ino_i);
-	return NULL;
+	return EOK;
 }
 
