Index: boot/Makefile.common
===================================================================
--- boot/Makefile.common	(revision 1f131fb920d7e3db267b4e541a60b10999e98b0e)
+++ boot/Makefile.common	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -75,5 +75,8 @@
 	$(USPACE_PATH)/srv/loc/loc \
 	$(USPACE_PATH)/srv/bd/rd/rd \
-	$(USPACE_PATH)/srv/vfs/vfs
+	$(USPACE_PATH)/srv/vfs/vfs \
+	
+# TODO: For comfort ext4fs debugging - delete before merge	
+INIT_TASKS += $(USPACE_PATH)/srv/bd/ata_bd/ata_bd
 
 ifeq ($(RDFMT),tmpfs)
@@ -106,4 +109,5 @@
 	$(USPACE_PATH)/srv/fs/exfat/exfat \
 	$(USPACE_PATH)/srv/fs/ext2fs/ext2fs \
+	$(USPACE_PATH)/srv/fs/ext4fs/ext4fs \
 	$(USPACE_PATH)/srv/taskmon/taskmon \
 	$(USPACE_PATH)/srv/net/nil/eth/eth \
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 1f131fb920d7e3db267b4e541a60b10999e98b0e)
+++ uspace/Makefile	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -88,4 +88,5 @@
 	srv/fs/locfs \
 	srv/fs/ext2fs \
+	srv/fs/ext4fs \
 	srv/hid/console \
 	srv/hid/s3c24xx_ts \
@@ -185,4 +186,5 @@
 	lib/nic \
 	lib/ext2 \
+	lib/ext4 \
 	lib/usb \
 	lib/usbhost \
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision 1f131fb920d7e3db267b4e541a60b10999e98b0e)
+++ uspace/Makefile.common	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -115,4 +115,5 @@
 
 LIBEXT2_PREFIX = $(LIB_PREFIX)/ext2
+LIBEXT4_PREFIX = $(LIB_PREFIX)/ext4
 
 LIBUSB_PREFIX = $(LIB_PREFIX)/usb
Index: uspace/lib/ext4/Makefile
===================================================================
--- uspace/lib/ext4/Makefile	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/Makefile	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,43 @@
+#
+# Copyright (c) 2011 Frantisek Princ
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../..
+LIBRARY = libext4
+EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
+LIBS = $(LIBBLOCK_PREFIX)/libblock.a
+
+SOURCES = \
+	libext4_block_group.c \
+	libext4_directory.c \
+	libext4_extent.c \
+	libext4_filesystem.c \
+	libext4_inode.c \
+	libext4_superblock.c
+	
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/ext4/libext4.h
===================================================================
--- uspace/lib/ext4/libext4.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+#ifndef LIBEXT4_LIBEXT4_H_
+#define LIBEXT4_LIBEXT4_H_
+
+#include "libext4_block_group.h"
+#include "libext4_directory.h"
+#include "libext4_extent.h"
+#include "libext4_filesystem.h"
+#include "libext4_inode.h"
+#include "libext4_superblock.h"
+
+#include <stdio.h>
+#define EXT4FS_DBG(format, ...) {if (true) printf("ext4fs: %s: " format "\n", __FUNCTION__, ##__VA_ARGS__);}
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/ext4/libext4_block_group.c
===================================================================
--- uspace/lib/ext4/libext4_block_group.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_block_group.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+/**
+ * @file	libext4_block_group.c
+ * @brief	TODO
+ */
+
+#include <byteorder.h>
+#include "libext4.h"
+
+uint64_t ext4_block_group_get_block_bitmap(ext4_block_group_t *bg)
+{
+	return ((uint64_t)uint32_t_le2host(bg->block_bitmap_hi) << 32) |
+		uint32_t_le2host(bg->block_bitmap_lo);
+}
+
+uint64_t ext4_block_group_get_inode_bitmap(ext4_block_group_t *bg)
+{
+	return ((uint64_t)uint32_t_le2host(bg->inode_bitmap_hi) << 32) |
+		uint32_t_le2host(bg->inode_bitmap_lo);
+}
+
+uint64_t ext4_block_group_get_inode_table_first_block(ext4_block_group_t *bg)
+{
+	return ((uint64_t)uint32_t_le2host(bg->inode_table_first_block_hi) << 32) |
+		uint32_t_le2host(bg->inode_table_first_block_lo);
+}
+
+uint32_t ext4_block_group_get_free_blocks_count(ext4_block_group_t *bg)
+{
+	return ((uint32_t)uint16_t_le2host(bg->free_blocks_count_hi) << 16) |
+		uint16_t_le2host(bg->free_blocks_count_lo);
+}
+
+uint32_t ext4_block_group_get_free_inodes_count(ext4_block_group_t *bg)
+{
+	return ((uint32_t)uint16_t_le2host(bg->free_inodes_count_hi) << 16) |
+		uint16_t_le2host(bg->free_inodes_count_lo);
+}
+
+uint32_t ext4_block_group_get_used_dirs_count(ext4_block_group_t *bg)
+{
+	return ((uint32_t)uint16_t_le2host(bg->used_dirs_count_hi) << 16) |
+		uint16_t_le2host(bg->used_dirs_count_lo);
+}
+
+uint16_t ext4_block_group_get_flags(ext4_block_group_t *bg)
+{
+	return uint16_t_le2host(bg->flags);
+}
+
+uint32_t ext4_block_group_get_itable_unused(ext4_block_group_t *bg)
+{
+	return ((uint32_t)uint16_t_le2host(bg->itable_unused_hi) << 16) |
+		uint16_t_le2host(bg->itable_unused_lo);
+}
+
+uint16_t ext4_block_group_get_checksum(ext4_block_group_t *bg)
+{
+	return uint16_t_le2host(bg->checksum);
+}
+
+/**
+ * @}
+ */ 
Index: uspace/lib/ext4/libext4_block_group.h
===================================================================
--- uspace/lib/ext4/libext4_block_group.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_block_group.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+#ifndef LIBEXT4_LIBEXT4_BLOCK_GROUP_H_
+#define LIBEXT4_LIBEXT4_BLOCK_GROUP_H_
+
+#include <libblock.h>
+#include <sys/types.h>
+#include "libext4_block_group.h"
+/*
+ * Structure of a blocks group descriptor
+ */
+typedef struct ext4_block_group {
+	uint32_t block_bitmap_lo; // Blocks bitmap block
+	uint32_t inode_bitmap_lo; // Inodes bitmap block
+	uint32_t inode_table_first_block_lo; // Inodes table block
+	uint16_t free_blocks_count_lo; // Free blocks count
+	uint16_t free_inodes_count_lo; // Free inodes count
+	uint16_t used_dirs_count_lo; // Directories count
+	uint16_t flags; // EXT4_BG_flags (INODE_UNINIT, etc)
+	uint32_t reserved[2]; // Likely block/inode bitmap checksum
+	uint16_t itable_unused_lo; // Unused inodes count
+	uint16_t checksum; // crc16(sb_uuid+group+desc)
+	uint32_t block_bitmap_hi; // Blocks bitmap block MSB
+	uint32_t inode_bitmap_hi; // Inodes bitmap block MSB
+	uint32_t inode_table_first_block_hi; // Inodes table block MSB
+	uint16_t free_blocks_count_hi; // Free blocks count MSB
+	uint16_t free_inodes_count_hi; // Free inodes count MSB
+	uint16_t used_dirs_count_hi; // Directories count MSB
+	uint16_t itable_unused_hi;  // Unused inodes count MSB
+	uint32_t reserved2[3]; // Padding
+} ext4_block_group_t;
+
+typedef struct ext4_block_group_ref {
+	block_t *block; // Reference to a block containing this block group descr
+	ext4_block_group_t *block_group;
+} ext4_block_group_ref_t;
+
+// TODO check value
+#define EXT4_BLOCK_GROUP_DESCRIPTOR_SIZE 32
+
+extern uint64_t ext4_block_group_get_block_bitmap(ext4_block_group_t *);
+extern uint64_t ext4_block_group_get_inode_bitmap(ext4_block_group_t *);
+extern uint64_t ext4_block_group_get_inode_table_first_block(ext4_block_group_t *);
+extern uint32_t ext4_block_group_get_free_blocks_count(ext4_block_group_t *);
+extern uint32_t ext4_block_group_get_free_inodes_count(ext4_block_group_t *);
+extern uint32_t ext4_block_group_get_used_dirs_count(ext4_block_group_t *);
+extern uint16_t ext4_block_group_get_flags(ext4_block_group_t *);
+extern uint32_t ext4_block_group_get_itable_unused(ext4_block_group_t *);
+extern uint16_t ext4_block_group_get_checksum(ext4_block_group_t *);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/ext4/libext4_directory.c
===================================================================
--- uspace/lib/ext4/libext4_directory.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_directory.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+/**
+ * @file	libext4_directory.c
+ * @brief	TODO
+ */
+
+#include <byteorder.h>
+#include <errno.h>
+#include "libext4.h"
+
+static int ext4_directory_iterator_set(ext4_directory_iterator_t *,
+    uint32_t);
+
+
+uint32_t ext4_directory_entry_ll_get_inode(ext4_directory_entry_ll_t *de)
+{
+	return uint32_t_le2host(de->inode);
+}
+
+uint16_t ext4_directory_entry_ll_get_entry_length(
+    ext4_directory_entry_ll_t *de)
+{
+	return uint16_t_le2host(de->entry_length);
+}
+
+uint16_t ext4_directory_entry_ll_get_name_length(
+    ext4_superblock_t *sb, ext4_directory_entry_ll_t *de)
+{
+	if (ext4_superblock_get_rev_level(sb) == 0 &&
+	    ext4_superblock_get_minor_rev_level(sb) < 5) {
+		return ((uint16_t)de->name_length_high) << 8 |
+		    ((uint16_t)de->name_length);
+	}
+	return de->name_length;
+}
+
+int ext4_directory_iterator_init(ext4_directory_iterator_t *it,
+    ext4_filesystem_t *fs, ext4_inode_ref_t *inode_ref, aoff64_t pos)
+{
+	it->inode_ref = inode_ref;
+	it->fs = fs;
+	it->current = NULL;
+	it->current_offset = 0;
+	it->current_block = NULL;
+
+	return ext4_directory_iterator_seek(it, pos);
+}
+
+
+int ext4_directory_iterator_next(ext4_directory_iterator_t *it)
+{
+	uint16_t skip;
+
+	assert(it->current != NULL);
+
+	skip = ext4_directory_entry_ll_get_entry_length(it->current);
+
+	return ext4_directory_iterator_seek(it, it->current_offset + skip);
+}
+
+
+int ext4_directory_iterator_seek(ext4_directory_iterator_t *it, aoff64_t pos)
+{
+	int rc;
+
+	uint64_t size;
+	aoff64_t current_block_idx;
+	aoff64_t next_block_idx;
+	uint32_t next_block_phys_idx;
+	uint32_t block_size;
+
+	size = ext4_inode_get_size(it->fs->superblock, it->inode_ref->inode);
+
+	/* The iterator is not valid until we seek to the desired position */
+	it->current = NULL;
+
+	/* Are we at the end? */
+	if (pos >= size) {
+		if (it->current_block) {
+			rc = block_put(it->current_block);
+			it->current_block = NULL;
+			if (rc != EOK) {
+				return rc;
+			}
+		}
+
+		it->current_offset = pos;
+		return EOK;
+	}
+
+	block_size = ext4_superblock_get_block_size(it->fs->superblock);
+	current_block_idx = it->current_offset / block_size;
+	next_block_idx = pos / block_size;
+
+	/* If we don't have a block or are moving accross block boundary,
+	 * we need to get another block
+	 */
+	if (it->current_block == NULL || current_block_idx != next_block_idx) {
+		if (it->current_block) {
+			rc = block_put(it->current_block);
+			it->current_block = NULL;
+			if (rc != EOK) {
+				return rc;
+			}
+		}
+
+		rc = ext4_filesystem_get_inode_data_block_index(it->fs,
+		    it->inode_ref->inode, next_block_idx, &next_block_phys_idx);
+		if (rc != EOK) {
+			return rc;
+		}
+
+		rc = block_get(&it->current_block, it->fs->device, next_block_phys_idx,
+		    BLOCK_FLAGS_NONE);
+		if (rc != EOK) {
+			it->current_block = NULL;
+			return rc;
+		}
+	}
+
+	it->current_offset = pos;
+
+	return ext4_directory_iterator_set(it, block_size);
+}
+
+static int ext4_directory_iterator_set(ext4_directory_iterator_t *it,
+    uint32_t block_size)
+{
+	uint32_t offset_in_block = it->current_offset % block_size;
+
+	it->current = NULL;
+
+	/* Ensure proper alignment */
+	if ((offset_in_block % 4) != 0) {
+		return EIO;
+	}
+
+	/* Ensure that the core of the entry does not overflow the block */
+	if (offset_in_block > block_size - 8) {
+		return EIO;
+	}
+
+	ext4_directory_entry_ll_t *entry = it->current_block->data + offset_in_block;
+
+	/* Ensure that the whole entry does not overflow the block */
+	uint16_t length = ext4_directory_entry_ll_get_entry_length(entry);
+	if (offset_in_block + length > block_size) {
+		return EIO;
+	}
+
+	/* Ensure the name length is not too large */
+	if (ext4_directory_entry_ll_get_name_length(it->fs->superblock,
+	    entry) > length-8) {
+		return EIO;
+	}
+
+	it->current = entry;
+	return EOK;
+}
+
+
+int ext4_directory_iterator_fini(ext4_directory_iterator_t *it)
+{
+	int rc;
+
+	it->fs = NULL;
+	it->inode_ref = NULL;
+	it->current = NULL;
+
+	if (it->current_block) {
+		rc = block_put(it->current_block);
+		if (rc != EOK) {
+			return rc;
+		}
+	}
+
+	return EOK;
+}
+
+
+/**
+ * @}
+ */ 
Index: uspace/lib/ext4/libext4_directory.h
===================================================================
--- uspace/lib/ext4/libext4_directory.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_directory.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+#ifndef LIBEXT4_LIBEXT4_DIRECTORY_H_
+#define LIBEXT4_LIBEXT4_DIRECTORY_H_
+
+#include "libext4_filesystem.h"
+#include "libext4_inode.h"
+
+#define EXT4_FILENAME_LEN	255
+
+/**
+ * Linked list directory entry structure
+ */
+typedef struct ext4_directory_entry_ll {
+	uint32_t inode; // Inode for the entry
+	uint16_t entry_length; // Distance to the next directory entry
+	uint8_t name_length; // Lower 8 bits of name length
+	union {
+		uint8_t name_length_high; // Higher 8 bits of name length
+		uint8_t inode_type; // Type of referenced inode (in rev >= 0.5)
+	} __attribute__ ((packed));
+	uint8_t name[EXT4_FILENAME_LEN]; // Entry name
+} __attribute__ ((packed)) ext4_directory_entry_ll_t;
+
+typedef struct ext4_directory_iterator {
+	ext4_filesystem_t *fs;
+	ext4_inode_ref_t *inode_ref;
+	block_t *current_block;
+	aoff64_t current_offset;
+	ext4_directory_entry_ll_t *current;
+} ext4_directory_iterator_t;
+
+extern uint32_t	ext4_directory_entry_ll_get_inode(ext4_directory_entry_ll_t *);
+extern uint16_t	ext4_directory_entry_ll_get_entry_length(
+    ext4_directory_entry_ll_t *);
+extern uint16_t	ext4_directory_entry_ll_get_name_length(
+    ext4_superblock_t *, ext4_directory_entry_ll_t *);
+
+extern int ext4_directory_iterator_init(ext4_directory_iterator_t *,
+		ext4_filesystem_t *, ext4_inode_ref_t *, aoff64_t);
+extern int ext4_directory_iterator_next(ext4_directory_iterator_t *);
+extern int ext4_directory_iterator_seek(ext4_directory_iterator_t *, aoff64_t pos);
+extern int ext4_directory_iterator_fini(ext4_directory_iterator_t *);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/ext4/libext4_extent.c
===================================================================
--- uspace/lib/ext4/libext4_extent.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_extent.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+/**
+ * @file	libext4_extent.c
+ * @brief	TODO
+ */
+
+#include <byteorder.h>
+#include "libext4_extent.h"
+
+uint32_t ext4_extent_get_first_block(ext4_extent_t *extent)
+{
+	return uint32_t_le2host(extent->first_block);
+}
+
+uint16_t ext4_extent_get_block_count(ext4_extent_t *extent)
+{
+	return uint16_t_le2host(extent->block_count);
+}
+
+uint64_t ext4_extent_get_start(ext4_extent_t *extent)
+{
+	return ((uint64_t)uint16_t_le2host(extent->start_hi)) << 32 |
+			((uint64_t)uint32_t_le2host(extent->start_lo));
+
+}
+
+uint32_t ext4_extent_index_get_first_block(ext4_extent_index_t *index)
+{
+	return uint32_t_le2host(index->first_block);
+}
+
+uint64_t ext4_extent_index_get_leaf(ext4_extent_index_t *index)
+{
+	return ((uint64_t)uint16_t_le2host(index->leaf_hi)) << 32 |
+				((uint64_t)uint32_t_le2host(index->leaf_lo));
+}
+
+uint16_t ext4_extent_header_get_magic(ext4_extent_header_t *header)
+{
+	return uint16_t_le2host(header->magic);
+}
+
+uint16_t ext4_extent_header_get_entries_count(ext4_extent_header_t *header)
+{
+	return uint16_t_le2host(header->entries_count);
+}
+
+uint16_t ext4_extent_header_get_max_entries_count(ext4_extent_header_t *header)
+{
+	return uint16_t_le2host(header->max_entries_count);
+}
+
+uint16_t ext4_extent_header_get_depth(ext4_extent_header_t *header)
+{
+	return uint16_t_le2host(header->depth);
+}
+
+uint32_t ext4_extent_header_get_generation(ext4_extent_header_t *header)
+{
+	return uint32_t_le2host(header->generation);
+}
+
+/**
+ * @}
+ */ 
Index: uspace/lib/ext4/libext4_extent.h
===================================================================
--- uspace/lib/ext4/libext4_extent.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_extent.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+#ifndef LIBEXT4_LIBEXT4_EXTENT_H_
+#define LIBEXT4_LIBEXT4_EXTENT_H_
+
+/*
+ * This is the extent on-disk structure.
+ * It's used at the bottom of the tree.
+ */
+typedef struct ext4_extent {
+	uint32_t first_block; // First logical block extent covers
+	uint16_t block_count; // Number of blocks covered by extent
+	uint16_t start_hi;    // High 16 bits of physical block
+	uint32_t start_lo;    // Low 32 bits of physical block
+} ext4_extent_t;
+
+/*
+ * This is index on-disk structure.
+ * It's used at all the levels except the bottom.
+ */
+typedef struct ext4_extent_index {
+	uint32_t first_block; // Index covers logical blocks from 'block'
+	uint32_t leaf_lo; /* Pointer to the physical block of the next
+	 	 	 	 	   * level. leaf or next index could be there */
+	uint16_t leaf_hi;     /* high 16 bits of physical block */
+	uint16_t padding;
+} ext4_extent_index_t;
+
+/*
+ * Each block (leaves and indexes), even inode-stored has header.
+ */
+typedef struct ext4_extent_header {
+	uint16_t magic;
+	uint16_t entries_count; // Number of valid entries
+	uint16_t max_entries_count; // Capacity of store in entries
+	uint16_t depth; // Has tree real underlying blocks?
+	uint32_t generation; // generation of the tree
+} ext4_extent_header_t;
+
+#define EXT4_EXTENT_MAGIC	0xF30A
+#define	EXT4_EXTENT_FIRST(header)	\
+		((ext4_extent_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
+#define	EXT4_EXTENT_FIRST_INDEX(header)	\
+		((ext4_extent_index_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
+
+extern uint32_t ext4_extent_get_first_block(ext4_extent_t *);
+extern uint16_t ext4_extent_get_block_count(ext4_extent_t *);
+extern uint64_t ext4_extent_get_start(ext4_extent_t *);
+
+extern uint32_t ext4_extent_index_get_first_block(ext4_extent_index_t *);
+extern uint64_t ext4_extent_index_get_leaf(ext4_extent_index_t *);
+
+extern uint16_t ext4_extent_header_get_magic(ext4_extent_header_t *);
+extern uint16_t ext4_extent_header_get_entries_count(ext4_extent_header_t *);
+extern uint16_t ext4_extent_header_get_max_entries_count(ext4_extent_header_t *);
+extern uint16_t ext4_extent_header_get_depth(ext4_extent_header_t *);
+extern uint32_t ext4_extent_header_get_generation(ext4_extent_header_t *);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/ext4/libext4_filesystem.c
===================================================================
--- uspace/lib/ext4/libext4_filesystem.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_filesystem.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,393 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+/**
+ * @file	libext4_filesystem.c
+ * @brief	TODO
+ */
+
+#include <byteorder.h>
+#include <errno.h>
+#include <malloc.h>
+#include "libext4.h"
+
+int ext4_filesystem_init(ext4_filesystem_t *fs, service_id_t service_id)
+{
+
+	int rc;
+	ext4_superblock_t *temp_superblock;
+	size_t block_size;
+
+	fs->device = service_id;
+
+	// TODO what does constant 2048 mean?
+	rc = block_init(EXCHANGE_SERIALIZE, fs->device, 2048);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	/* Read superblock from device */
+	rc = ext4_superblock_read_direct(fs->device, &temp_superblock);
+	if (rc != EOK) {
+		block_fini(fs->device);
+		return rc;
+	}
+
+	/* Read block size from superblock and check */
+	block_size = ext4_superblock_get_block_size(temp_superblock);
+	if (block_size > EXT4_MAX_BLOCK_SIZE) {
+		block_fini(fs->device);
+		return ENOTSUP;
+	}
+
+	/* Initialize block caching */
+	rc = block_cache_init(service_id, block_size, 0, CACHE_MODE_WT);
+	if (rc != EOK) {
+		block_fini(fs->device);
+		return rc;
+	}
+
+	/* Return loaded superblock */
+	fs->superblock = temp_superblock;
+
+	return EOK;
+}
+
+void ext4_filesystem_fini(ext4_filesystem_t *fs)
+{
+	free(fs->superblock);
+	block_fini(fs->device);
+}
+
+int ext4_filesystem_check_sanity(ext4_filesystem_t *fs)
+{
+	int rc;
+
+	rc = ext4_superblock_check_sanity(fs->superblock);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	return EOK;
+}
+
+int ext4_filesystem_check_features(ext4_filesystem_t *fs, bool *o_read_only)
+{
+	/* Feature flags are present in rev 1 and later */
+	if (ext4_superblock_get_rev_level(fs->superblock) == 0) {
+		*o_read_only = false;
+		return EOK;
+	}
+
+	uint32_t incompatible_features;
+	incompatible_features = ext4_superblock_get_features_incompatible(fs->superblock);
+	incompatible_features &= ~EXT4_FEATURE_INCOMPAT_SUPP;
+	if (incompatible_features > 0) {
+		*o_read_only = true;
+		return ENOTSUP;
+	}
+
+	uint32_t compatible_read_only;
+	compatible_read_only = ext4_superblock_get_features_read_only(fs->superblock);
+	compatible_read_only &= ~EXT4_FEATURE_RO_COMPAT_SUPP;
+	if (compatible_read_only > 0) {
+		*o_read_only = true;
+	}
+
+	return EOK;
+}
+
+// Feature checkers
+bool ext4_filesystem_has_feature_compatible(ext4_filesystem_t *fs, uint32_t feature)
+{
+	ext4_superblock_t *sb = fs->superblock;
+
+	if (ext4_superblock_get_features_compatible(sb) & feature) {
+		return true;
+	}
+	return false;
+}
+
+bool ext4_filesystem_has_feature_incompatible(ext4_filesystem_t *fs, uint32_t feature)
+{
+	ext4_superblock_t *sb = fs->superblock;
+
+	if (ext4_superblock_get_features_incompatible(sb) & feature) {
+		return true;
+	}
+	return false;
+}
+
+bool ext4_filesystem_has_feature_read_only(ext4_filesystem_t *fs, uint32_t feature)
+{
+	ext4_superblock_t *sb = fs->superblock;
+
+	if (ext4_superblock_get_features_read_only(sb) & feature) {
+		return true;
+	}
+	return false;
+}
+
+
+int ext4_filesystem_get_block_group_ref(ext4_filesystem_t *fs, uint32_t bgid,
+    ext4_block_group_ref_t **ref)
+{
+	int rc;
+	aoff64_t block_id;
+	uint32_t descriptors_per_block;
+	size_t offset;
+	ext4_block_group_ref_t *newref;
+
+	newref = malloc(sizeof(ext4_block_group_ref_t));
+	if (newref == NULL) {
+		return ENOMEM;
+	}
+
+	descriptors_per_block = ext4_superblock_get_block_size(fs->superblock)
+	    / EXT4_BLOCK_GROUP_DESCRIPTOR_SIZE;
+
+	/* Block group descriptor table starts at the next block after superblock */
+	block_id = ext4_superblock_get_first_data_block(fs->superblock) + 1;
+
+	/* Find the block containing the descriptor we are looking for */
+	block_id += bgid / descriptors_per_block;
+	offset = (bgid % descriptors_per_block) * EXT4_BLOCK_GROUP_DESCRIPTOR_SIZE;
+
+	rc = block_get(&newref->block, fs->device, block_id, 0);
+	if (rc != EOK) {
+		free(newref);
+		return rc;
+	}
+
+	newref->block_group = newref->block->data + offset;
+
+	*ref = newref;
+
+	return EOK;
+}
+
+int ext4_filesystem_put_block_group_ref(ext4_block_group_ref_t *ref)
+{
+	int rc;
+
+	rc = block_put(ref->block);
+	free(ref);
+
+	return rc;
+}
+
+int ext4_filesystem_get_inode_ref(ext4_filesystem_t *fs, uint32_t index,
+    ext4_inode_ref_t **ref)
+{
+	int rc;
+	aoff64_t block_id;
+	uint32_t block_group;
+	uint32_t offset_in_group;
+	uint32_t byte_offset_in_group;
+	size_t offset_in_block;
+	uint32_t inodes_per_group;
+	uint32_t inode_table_start;
+	uint16_t inode_size;
+	uint32_t block_size;
+	ext4_block_group_ref_t *bg_ref;
+	ext4_inode_ref_t *newref;
+
+	newref = malloc(sizeof(ext4_inode_ref_t));
+	if (newref == NULL) {
+		return ENOMEM;
+	}
+
+	inodes_per_group = ext4_superblock_get_inodes_per_group(fs->superblock);
+
+	/* inode numbers are 1-based, but it is simpler to work with 0-based
+	 * when computing indices
+	 */
+	index -= 1;
+	block_group = index / inodes_per_group;
+	offset_in_group = index % inodes_per_group;
+
+	rc = ext4_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
+	if (rc != EOK) {
+		free(newref);
+		return rc;
+	}
+
+	inode_table_start = ext4_block_group_get_inode_table_first_block(
+	    bg_ref->block_group);
+
+	rc = ext4_filesystem_put_block_group_ref(bg_ref);
+	if (rc != EOK) {
+		free(newref);
+		return rc;
+	}
+
+	inode_size = ext4_superblock_get_inode_size(fs->superblock);
+	block_size = ext4_superblock_get_block_size(fs->superblock);
+
+	byte_offset_in_group = offset_in_group * inode_size;
+
+	block_id = inode_table_start + (byte_offset_in_group / block_size);
+	offset_in_block = byte_offset_in_group % block_size;
+
+	rc = block_get(&newref->block, fs->device, block_id, 0);
+	if (rc != EOK) {
+		free(newref);
+		return rc;
+	}
+
+	newref->inode = newref->block->data + offset_in_block;
+	/* we decremented index above, but need to store the original value
+	 * in the reference
+	 */
+	newref->index = index+1;
+
+	*ref = newref;
+
+	return EOK;
+}
+
+
+int ext4_filesystem_put_inode_ref(ext4_inode_ref_t *ref)
+{
+	int rc;
+
+	rc = block_put(ref->block);
+	free(ref);
+
+	return rc;
+}
+
+int ext4_filesystem_get_inode_data_block_index(ext4_filesystem_t *fs, ext4_inode_t* inode,
+    aoff64_t iblock, uint32_t* fblock)
+{
+	int rc;
+	aoff64_t limits[4];
+	uint32_t block_ids_per_block;
+	aoff64_t blocks_per_level[4];
+	uint32_t offset_in_block;
+	uint32_t current_block;
+	aoff64_t block_offset_in_level;
+	int i;
+	int level;
+	block_t *block;
+
+	/* Handle inode using extents */
+	// TODO check "extents" feature in superblock ???
+	if (ext4_inode_has_flag(inode, EXT4_INODE_FLAG_EXTENTS)) {
+		current_block = ext4_inode_get_extent_block(inode, iblock, fs->device);
+		*fblock = current_block;
+		return EOK;
+
+	}
+
+	/* Handle simple case when we are dealing with direct reference */
+	if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
+		current_block = ext4_inode_get_direct_block(inode, (uint32_t)iblock);
+		*fblock = current_block;
+		return EOK;
+	}
+
+	/* Compute limits for indirect block levels
+	 * TODO: compute this once when loading filesystem and store in ext2_filesystem_t
+	 */
+	block_ids_per_block = ext4_superblock_get_block_size(fs->superblock) / sizeof(uint32_t);
+	limits[0] = EXT4_INODE_DIRECT_BLOCK_COUNT;
+	blocks_per_level[0] = 1;
+	for (i = 1; i < 4; i++) {
+		blocks_per_level[i]  = blocks_per_level[i-1] *
+		    block_ids_per_block;
+		limits[i] = limits[i-1] + blocks_per_level[i];
+	}
+
+	/* Determine the indirection level needed to get the desired block */
+	level = -1;
+	for (i = 1; i < 4; i++) {
+		if (iblock < limits[i]) {
+			level = i;
+			break;
+		}
+	}
+
+	if (level == -1) {
+		return EIO;
+	}
+
+	/* Compute offsets for the topmost level */
+	block_offset_in_level = iblock - limits[level-1];
+	current_block = ext4_inode_get_indirect_block(inode, level-1);
+	offset_in_block = block_offset_in_level / blocks_per_level[level-1];
+
+	/* Navigate through other levels, until we find the block number
+	 * or find null reference meaning we are dealing with sparse file
+	 */
+	while (level > 0) {
+		rc = block_get(&block, fs->device, current_block, 0);
+		if (rc != EOK) {
+			return rc;
+		}
+
+		assert(offset_in_block < block_ids_per_block);
+		current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
+
+		rc = block_put(block);
+		if (rc != EOK) {
+			return rc;
+		}
+
+		if (current_block == 0) {
+			/* This is a sparse file */
+			*fblock = 0;
+			return EOK;
+		}
+
+		level -= 1;
+
+		/* If we are on the last level, break here as
+		 * there is no next level to visit
+		 */
+		if (level == 0) {
+			break;
+		}
+
+		/* Visit the next level */
+		block_offset_in_level %= blocks_per_level[level];
+		offset_in_block = block_offset_in_level / blocks_per_level[level-1];
+	}
+
+	*fblock = current_block;
+
+	return EOK;
+}
+
+/**
+ * @}
+ */ 
Index: uspace/lib/ext4/libext4_filesystem.h
===================================================================
--- uspace/lib/ext4/libext4_filesystem.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_filesystem.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+#ifndef LIBEXT4_LIBEXT4_FILESYSTEM_H_
+#define LIBEXT4_LIBEXT4_FILESYSTEM_H_
+
+#include <libblock.h>
+#include "libext4_block_group.h"
+#include "libext4_inode.h"
+#include "libext4_superblock.h"
+
+typedef struct ext4_filesystem {
+	service_id_t device;
+	ext4_superblock_t *	superblock;
+} ext4_filesystem_t;
+
+#define EXT4_MAX_BLOCK_SIZE 	65536 //64 KiB
+#define EXT4_REV0_INODE_SIZE	128
+
+/* Compatible features */
+// TODO features comments !!!
+#define EXT4_FEATURE_COMPAT_DIR_PREALLOC        0x0001
+#define EXT4_FEATURE_COMPAT_IMAGIC_INODES       0x0002
+#define EXT4_FEATURE_COMPAT_HAS_JOURNAL         0x0004
+#define EXT4_FEATURE_COMPAT_EXT_ATTR            0x0008
+#define EXT4_FEATURE_COMPAT_RESIZE_INODE        0x0010
+#define EXT4_FEATURE_COMPAT_DIR_INDEX           0x0020
+
+/* Read-only compatible features */
+// TODO features comments !!!
+#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER     0x0001
+#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE       0x0002
+#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR        0x0004
+#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE        0x0008
+#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM         0x0010
+#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK        0x0020
+#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE      0x0040
+
+/* Incompatible features */
+// TODO features comments !!!
+#define EXT4_FEATURE_INCOMPAT_COMPRESSION       0x0001
+#define EXT4_FEATURE_INCOMPAT_FILETYPE          0x0002
+#define EXT4_FEATURE_INCOMPAT_RECOVER           0x0004 /* Needs recovery */
+#define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV       0x0008 /* Journal device */
+#define EXT4_FEATURE_INCOMPAT_META_BG           0x0010
+#define EXT4_FEATURE_INCOMPAT_EXTENTS           0x0040 /* extents support */
+#define EXT4_FEATURE_INCOMPAT_64BIT             0x0080
+#define EXT4_FEATURE_INCOMPAT_MMP               0x0100
+#define EXT4_FEATURE_INCOMPAT_FLEX_BG           0x0200
+#define EXT4_FEATURE_INCOMPAT_EA_INODE          0x0400 /* EA in inode */
+#define EXT4_FEATURE_INCOMPAT_DIRDATA           0x1000 /* data in dirent */
+
+
+// TODO MODIFY features corresponding with implementation
+#define EXT4_FEATURE_COMPAT_SUPP EXT4_FEATURE_COMPAT_EXT_ATTR
+
+#define EXT4_FEATURE_INCOMPAT_SUPP      (EXT4_FEATURE_INCOMPAT_FILETYPE| \
+                                         EXT4_FEATURE_INCOMPAT_RECOVER| \
+                                         EXT4_FEATURE_INCOMPAT_META_BG| \
+                                         EXT4_FEATURE_INCOMPAT_EXTENTS| \
+                                         EXT4_FEATURE_INCOMPAT_64BIT| \
+                                         EXT4_FEATURE_INCOMPAT_FLEX_BG)
+
+#define EXT4_FEATURE_RO_COMPAT_SUPP     (EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER| \
+                                         EXT4_FEATURE_RO_COMPAT_LARGE_FILE| \
+                                         EXT4_FEATURE_RO_COMPAT_GDT_CSUM| \
+                                         EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \
+                                         EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \
+                                         EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\
+                                         EXT4_FEATURE_RO_COMPAT_HUGE_FILE)
+
+
+extern int ext4_filesystem_init(ext4_filesystem_t *, service_id_t);
+extern void ext4_filesystem_fini(ext4_filesystem_t *fs);
+extern int ext4_filesystem_check_sanity(ext4_filesystem_t *fs);
+extern int ext4_filesystem_check_features(ext4_filesystem_t *, bool *);
+extern bool ext4_filesystem_has_feature_compatible(ext4_filesystem_t *, uint32_t);
+extern bool ext4_filesystem_has_feature_incompatible(ext4_filesystem_t *, uint32_t);
+extern bool ext4_filesystem_has_feature_read_only(ext4_filesystem_t *, uint32_t);
+extern int ext4_filesystem_get_block_group_ref(ext4_filesystem_t *, uint32_t,
+    ext4_block_group_ref_t **);
+extern int ext4_filesystem_put_block_group_ref(ext4_block_group_ref_t *);
+extern int ext4_filesystem_get_inode_ref(ext4_filesystem_t *, uint32_t,
+		ext4_inode_ref_t **);
+extern int ext4_filesystem_put_inode_ref(ext4_inode_ref_t *);
+extern int ext4_filesystem_get_inode_data_block_index(ext4_filesystem_t *,
+	ext4_inode_t *, aoff64_t iblock, uint32_t *);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/ext4/libext4_inode.c
===================================================================
--- uspace/lib/ext4/libext4_inode.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_inode.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+/**
+ * @file	libext4_inode.c
+ * @brief	Ext4 inode operations.
+ */
+
+#include <byteorder.h>
+#include <errno.h>
+#include <libblock.h>
+#include "libext4.h"
+
+uint32_t ext4_inode_get_mode(ext4_superblock_t *sb, ext4_inode_t *inode)
+{
+	if (ext4_superblock_get_creator_os(sb) == EXT4_SUPERBLOCK_OS_HURD) {
+		return ((uint32_t)uint16_t_le2host(inode->osd2.hurd2.mode_high)) << 16 |
+		    ((uint32_t)uint16_t_le2host(inode->mode));
+	}
+	return uint16_t_le2host(inode->mode);
+}
+
+bool ext4_inode_is_type(ext4_superblock_t *sb, ext4_inode_t *inode, uint32_t type)
+{
+	uint32_t mode = ext4_inode_get_mode(sb, inode);
+	return (mode & EXT4_INODE_MODE_TYPE_MASK) == type;
+}
+
+/*
+uint32_t ext4_inode_get_uid(ext4_inode_t *inode)
+*/
+
+uint64_t ext4_inode_get_size(ext4_superblock_t *sb, ext4_inode_t *inode)
+{
+	uint32_t major_rev = ext4_superblock_get_rev_level(sb);
+
+	if ((major_rev > 0) && ext4_inode_is_type(sb, inode, EXT4_INODE_MODE_FILE)) {
+		return ((uint64_t)uint32_t_le2host(inode->size_hi)) << 32 |
+			    ((uint64_t)uint32_t_le2host(inode->size_lo));
+		}
+	return uint32_t_le2host(inode->size_lo);
+}
+
+/*
+extern uint32_t ext4_inode_get_access_time(ext4_inode_t *);
+extern uint32_t ext4_inode_get_change_inode_time(ext4_inode_t *);
+extern uint32_t ext4_inode_get_modification_time(ext4_inode_t *);
+extern uint32_t ext4_inode_get_deletion_time(ext4_inode_t *);
+extern uint32_t ext4_inode_get_gid(ext4_inode_t *);
+*/
+
+uint16_t ext4_inode_get_links_count(ext4_inode_t *inode)
+{
+	return uint16_t_le2host(inode->links_count);
+}
+
+/*
+extern uint64_t ext4_inode_get_blocks_count(ext4_inode_t *);
+*/
+
+uint32_t ext4_inode_get_flags(ext4_inode_t *inode) {
+	return uint32_t_le2host(inode->flags);
+}
+
+uint32_t ext4_inode_get_direct_block(ext4_inode_t *inode, uint8_t idx)
+{
+	assert(idx < EXT4_INODE_DIRECT_BLOCK_COUNT);
+	return uint32_t_le2host(inode->blocks[idx]);
+}
+
+uint32_t ext4_inode_get_indirect_block(ext4_inode_t *inode, uint8_t idx)
+{
+	assert(idx < EXT4_INODE_INDIRECT_BLOCK_COUNT);
+	return uint32_t_le2host(inode->blocks[idx + EXT4_INODE_INDIRECT_BLOCK]);
+}
+
+uint32_t ext4_inode_get_extent_block(ext4_inode_t *inode, uint64_t idx, service_id_t service_id)
+{
+	ext4_extent_header_t *header = ext4_inode_get_extent_header(inode);
+	ext4_extent_t *extent;
+	ext4_extent_index_t *extent_index;
+
+	uint32_t first_block;
+	uint16_t block_count;
+	uint64_t phys_block = 0;
+	uint64_t child;
+
+	int rc;
+	block_t* block = NULL;
+
+	while (ext4_extent_header_get_depth(header) != 0) {
+
+		extent_index = EXT4_EXTENT_FIRST_INDEX(header);
+
+		for (uint16_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i) {
+			if(idx >= ext4_extent_index_get_first_block(extent_index)) {
+
+				child = ext4_extent_index_get_leaf(extent_index);
+
+				if (block != NULL) {
+					block_put(block);
+				}
+
+				rc = block_get(&block, service_id, child, BLOCK_FLAGS_NONE);
+				if (rc != EOK) {
+					return 0;
+				}
+				EXT4FS_DBG("get block");
+
+
+				header = (ext4_extent_header_t *)block->data;
+				break;
+			}
+		}
+	}
+
+	extent = EXT4_EXTENT_FIRST(header);
+
+	for (uint16_t i = 0; i < ext4_extent_header_get_entries_count(header); ++i) {
+
+		first_block = ext4_extent_get_first_block(extent);
+		block_count = ext4_extent_get_block_count(extent);
+
+		if ((idx >= first_block) && (idx < first_block + block_count)) {
+			phys_block = ext4_extent_get_start(extent) + idx;
+			phys_block -= ext4_extent_get_first_block(extent);
+
+			// Memory leak prevention
+			if (block != NULL) {
+				block_put(block);
+			}
+			return phys_block;
+		}
+		// Go to the next extent
+		++extent;
+	}
+
+
+	EXT4FS_DBG("ERROR - reached function end");
+	return phys_block;
+}
+
+ext4_extent_header_t * ext4_inode_get_extent_header(ext4_inode_t *inode)
+{
+	return (ext4_extent_header_t *)inode->blocks;
+}
+
+// Flags checker
+bool ext4_inode_has_flag(ext4_inode_t *inode, uint32_t flag) {
+	if (ext4_inode_get_flags(inode) & flag) {
+		return true;
+	}
+	return false;
+}
+
+/**
+ * @}
+ */ 
Index: uspace/lib/ext4/libext4_inode.h
===================================================================
--- uspace/lib/ext4/libext4_inode.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_inode.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+#ifndef LIBEXT4_LIBEXT4_INODE_H_
+#define LIBEXT4_LIBEXT4_INODE_H_
+
+#include <libblock.h>
+#include <sys/types.h>
+#include "libext4_extent.h"
+#include "libext4_superblock.h"
+
+
+#define EXT4_INODE_DIRECT_BLOCK_COUNT		12
+#define EXT4_INODE_INDIRECT_BLOCK 			EXT4_INODE_DIRECT_BLOCK_COUNT
+#define EXT4_INODE_DOUBLE_INDIRECT_BLOCK	(EXT4_INODE_INDIRECT_BLOCK + 1)
+#define EXT4_INODE_TRIPPLE_INDIRECT_BLOCK	(EXT4_INODE_DOUBLE_INDIRECT_BLOCK + 1)
+#define EXT4_INODE_BLOCKS					(EXT4_INODE_TRIPPLE_INDIRECT_BLOCK + 1)
+#define EXT4_INODE_INDIRECT_BLOCK_COUNT		(EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
+
+/*
+ * Structure of an inode on the disk
+ */
+typedef struct ext4_inode {
+	uint16_t mode; // File mode
+	uint16_t uid; // Low 16 bits of owner uid
+	uint32_t size_lo; // Size in bytes
+	uint32_t acess_time; // Access time
+	uint32_t change_inode_time; // Inode change time
+	uint32_t modification_time; // Modification time
+	uint32_t deletion_time; // Deletion time
+	uint16_t gid; // Low 16 bits of group id
+	uint16_t links_count; // Links count
+	uint32_t blocks_count_lo; // Blocks count
+	uint32_t flags; // File flags
+	uint32_t unused_osd1; // OS dependent - not used in HelenOS
+    uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
+    uint32_t generation; // File version (for NFS)
+    uint32_t file_acl_lo; // File ACL
+    uint32_t size_hi;
+    uint32_t obso_faddr; // Obsoleted fragment address
+    union {
+    	struct {
+    		uint16_t blocks_high; /* were l_i_reserved1 */
+    		uint16_t file_acl_high;
+    		uint16_t uid_high;   /* these 2 fields */
+    		uint16_t gid_high;   /* were reserved2[0] */
+    		uint32_t reserved2;
+    	} linux2;
+    	struct {
+    		uint16_t reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
+    		uint16_t mode_high;
+    		uint16_t uid_high;
+    		uint16_t gid_high;
+    		uint32_t author;
+    	} hurd2;
+    	struct {
+    		uint16_t reserved1;  /* Obsoleted fragment number/size which are removed in ext4 */
+    		uint16_t file_acl_high;
+    		uint32_t reserved2[2];
+    	} masix2;
+    } __attribute__ ((packed)) osd2;
+
+    uint16_t extra_isize;
+    uint16_t pad1;
+    uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
+    uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
+    uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
+    uint32_t crtime; // File creation time
+    uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
+    uint32_t version_hi;   // High 32 bits for 64-bit version
+} __attribute__ ((packed)) ext4_inode_t;
+
+#define EXT4_INODE_MODE_FIFO		0x1000
+#define EXT4_INODE_MODE_CHARDEV		0x2000
+#define EXT4_INODE_MODE_DIRECTORY	0x4000
+#define EXT4_INODE_MODE_BLOCKDEV	0x6000
+#define EXT4_INODE_MODE_FILE		0x8000
+#define EXT4_INODE_MODE_SOFTLINK	0xA000
+#define EXT4_INODE_MODE_SOCKET		0xC000
+#define EXT4_INODE_MODE_TYPE_MASK	0xF000
+
+/*
+ * Inode flags
+ */
+#define EXT4_INODE_FLAG_SECRM		0x00000001 // Secure deletion
+#define EXT4_INODE_FLAG_UNRM		0x00000002 // Undelete
+#define EXT4_INODE_FLAG_COMPR		0x00000004 // Compress file
+#define EXT4_INODE_FLAG_SYNC		0x00000008 // Synchronous updates
+#define EXT4_INODE_FLAG_IMMUTABLE   0x00000010 // Immutable file
+#define EXT4_INODE_FLAG_APPEND		0x00000020 // writes to file may only append
+#define EXT4_INODE_FLAG_NODUMP		0x00000040 // do not dump file
+#define EXT4_INODE_FLAG_NOATIME		0x00000080 // do not update atime
+/* Compression flags */
+#define EXT4_INODE_FLAG_DIRTY		0x00000100
+#define EXT4_INODE_FLAG_COMPRBLK	0x00000200 // One or more compressed clusters
+#define EXT4_INODE_FLAG_NOCOMPR		0x00000400 // Don't compress
+#define EXT4_INODE_FLAG_ECOMPR		0x00000800 // Compression error
+/* End compression flags --- maybe not all used */
+#define EXT4_INODE_FLAG_INDEX		0x00001000 // hash-indexed directory
+#define EXT4_INODE_FLAG_IMAGIC		0x00002000 // AFS directory */
+#define EXT4_INODE_FLAG_JOURNAL_DATA	0x00004000 // File data should be journaled
+#define EXT4_INODE_FLAG_NOTAIL		0x00008000 // File tail should not be merged
+#define EXT4_INODE_FLAG_DIRSYNC		0x00010000 // Dirsync behaviour (directories only)
+#define EXT4_INODE_FLAG_TOPDIR		0x00020000 // Top of directory hierarchies
+#define EXT4_INODE_FLAG_HUGE_FILE	0x00040000 // Set to each huge file
+#define EXT4_INODE_FLAG_EXTENTS		0x00080000 // Inode uses extents
+#define EXT4_INODE_FLAG_EA_INODE	0x00200000 // Inode used for large EA
+#define EXT4_INODE_FLAG_EOFBLOCKS	0x00400000 // Blocks allocated beyond EOF
+#define EXT4_INODE_FLAG_RESERVED	0x80000000 // reserved for ext4 lib
+
+#define EXT4_INODE_ROOT_INDEX	2
+
+typedef struct ext4_inode_ref {
+	block_t *block; // Reference to a block containing this inode
+	ext4_inode_t *inode;
+	uint32_t index; // Index number of this inode
+} ext4_inode_ref_t;
+
+
+extern uint32_t ext4_inode_get_mode(ext4_superblock_t *, ext4_inode_t *);
+extern bool ext4_inode_is_type(ext4_superblock_t *, ext4_inode_t *, uint32_t);
+/*
+extern uint32_t ext4_inode_get_uid(ext4_inode_t *);
+*/
+extern uint64_t ext4_inode_get_size(ext4_superblock_t *, ext4_inode_t *);
+/*
+extern uint32_t ext4_inode_get_access_time(ext4_inode_t *);
+extern uint32_t ext4_inode_get_change_inode_time(ext4_inode_t *);
+extern uint32_t ext4_inode_get_modification_time(ext4_inode_t *);
+extern uint32_t ext4_inode_get_deletion_time(ext4_inode_t *);
+extern uint32_t ext4_inode_get_gid(ext4_inode_t *);
+*/
+extern uint16_t ext4_inode_get_links_count(ext4_inode_t *);
+/*
+extern uint64_t ext4_inode_get_blocks_count(ext4_inode_t *)
+*/
+extern uint32_t ext4_inode_get_flags(ext4_inode_t *);
+
+uint32_t ext4_inode_get_direct_block(ext4_inode_t *, uint8_t);
+uint32_t ext4_inode_get_indirect_block(ext4_inode_t *, uint8_t);
+uint32_t ext4_inode_get_extent_block(ext4_inode_t *, uint64_t, service_id_t);
+/*
+uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
+uint32_t generation;
+uint32_t file_acl_lo; // File ACL
+uint16_t extra_isize;
+uint32_t ctime_extra; // Extra change time (nsec << 2 | epoch)
+uint32_t mtime_extra; // Extra Modification time (nsec << 2 | epoch)
+uint32_t atime_extra; // Extra Access time (nsec << 2 | epoch)
+uint32_t crtime; // File creation time
+uint32_t crtime_extra; // Extra file creation time (nsec << 2 | epoch)
+uint32_t version_hi;   // High 32 bits for 64-bit version
+*/
+
+extern ext4_extent_header_t * ext4_inode_get_extent_header(ext4_inode_t *);
+extern bool ext4_inode_has_flag(ext4_inode_t *, uint32_t);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/ext4/libext4_superblock.c
===================================================================
--- uspace/lib/ext4/libext4_superblock.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_superblock.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,228 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */ 
+
+/**
+ * @file	libext4_superblock.c
+ * @brief	Ext4 superblock operations.
+ */
+
+#include <byteorder.h>
+#include <errno.h>
+#include <libblock.h>
+#include <malloc.h>
+#include "libext4.h"
+
+uint32_t ext4_superblock_get_inodes_count(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->inodes_count);
+}
+
+uint64_t ext4_superblock_get_blocks_count(ext4_superblock_t *sb)
+{
+	return ((uint64_t)uint32_t_le2host(sb->blocks_count_hi) << 32) |
+			uint32_t_le2host(sb->blocks_count_lo);
+}
+
+uint64_t ext4_superblock_get_reserved_blocks_count(ext4_superblock_t *sb)
+{
+	return ((uint64_t)uint32_t_le2host(sb->reserved_blocks_count_hi) << 32) |
+			uint32_t_le2host(sb->reserved_blocks_count_lo);
+}
+
+uint64_t ext4_superblock_get_free_blocks_count(ext4_superblock_t *sb)
+{
+	return ((uint64_t)uint32_t_le2host(sb->free_blocks_count_hi) << 32) |
+			uint32_t_le2host(sb->free_blocks_count_lo);
+}
+
+uint32_t ext4_superblock_get_free_inodes_count(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->free_inodes_count);
+}
+
+uint32_t ext4_superblock_get_first_data_block(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->first_data_block);
+}
+
+uint32_t ext4_superblock_get_log_block_size(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->log_block_size);
+}
+
+uint32_t ext4_superblock_get_block_size(ext4_superblock_t *sb)
+{
+	return 1024 << ext4_superblock_get_log_block_size(sb);
+}
+
+
+uint32_t ext4_superblock_get_blocks_per_group(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->blocks_per_group);
+}
+
+uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->inodes_per_group);
+}
+
+uint32_t ext4_superblock_get_mount_time(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->mount_time);
+}
+
+uint32_t ext4_superblock_get_write_time(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->write_time);
+}
+
+uint16_t ext4_superblock_get_mount_count(ext4_superblock_t *sb)
+{
+	return uint16_t_le2host(sb->mount_count);
+}
+
+uint16_t ext4_superblock_get_max_mount_count(ext4_superblock_t *sb)
+{
+	return uint16_t_le2host(sb->max_mount_count);
+}
+
+uint16_t ext4_superblock_get_magic(ext4_superblock_t *sb)
+{
+	return uint16_t_le2host(sb->magic);
+}
+
+uint16_t ext4_superblock_get_state(ext4_superblock_t *sb)
+{
+	return uint16_t_le2host(sb->state);
+}
+
+uint16_t ext4_superblock_get_errors(ext4_superblock_t *sb)
+{
+	return uint16_t_le2host(sb->errors);
+}
+
+
+uint16_t ext4_superblock_get_minor_rev_level(ext4_superblock_t *sb)
+{
+	return uint16_t_le2host(sb->minor_rev_level);
+}
+
+uint32_t ext4_superblock_get_last_check_time(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->last_check_time);
+}
+
+uint32_t ext4_superblock_get_check_interval(ext4_superblock_t *sb){
+	return uint32_t_le2host(sb->check_interval);
+}
+
+uint32_t ext4_superblock_get_creator_os(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->creator_os);
+}
+
+uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->rev_level);
+}
+
+uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *sb)
+{
+	if (ext4_superblock_get_rev_level(sb) == 0) {
+		return EXT4_REV0_INODE_SIZE;
+	}
+	return uint16_t_le2host(sb->inode_size);
+}
+
+uint16_t ext4_superblock_get_block_group_number(ext4_superblock_t *sb)
+{
+	return uint16_t_le2host(sb->block_group_number);
+}
+
+uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->features_compatible);
+}
+
+uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->features_incompatible);
+}
+
+uint32_t ext4_superblock_get_features_read_only(ext4_superblock_t *sb)
+{
+	return uint32_t_le2host(sb->features_read_only);
+}
+
+
+/*
+ * More complex superblock functions
+ */
+
+int ext4_superblock_read_direct(service_id_t service_id,
+    ext4_superblock_t **superblock)
+{
+	void *data;
+	int rc;
+
+	data = malloc(EXT4_SUPERBLOCK_SIZE);
+	if (data == NULL) {
+		return ENOMEM;
+	}
+
+	rc = block_read_bytes_direct(service_id, EXT4_SUPERBLOCK_OFFSET,
+	    EXT4_SUPERBLOCK_SIZE, data);
+
+	if (rc != EOK) {
+		free(data);
+		return rc;
+	}
+
+	(*superblock) = data;
+
+	return EOK;
+}
+
+int ext4_superblock_check_sanity(ext4_superblock_t *sb)
+{
+	if (ext4_superblock_get_magic(sb) != EXT4_SUPERBLOCK_MAGIC) {
+		return ENOTSUP;
+	}
+
+	// TODO more checks !!!
+
+	return EOK;
+}
+
+/**
+ * @}
+ */ 
Index: uspace/lib/ext4/libext4_superblock.h
===================================================================
--- uspace/lib/ext4/libext4_superblock.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/lib/ext4/libext4_superblock.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libext4
+ * @{
+ */
+
+#ifndef LIBEXT4_LIBEXT4_SUPERBLOCK_H_
+#define LIBEXT4_LIBEXT4_SUPERBLOCK_H_
+
+#include <libblock.h>
+#include <sys/types.h>
+
+/*
+ * Structure of the super block
+ */
+typedef struct ext4_superblock {
+	uint32_t inodes_count; // Inodes count
+	uint32_t blocks_count_lo; // Blocks count
+	uint32_t reserved_blocks_count_lo; // Reserved blocks count
+	uint32_t free_blocks_count_lo; // Free blocks count
+	uint32_t free_inodes_count; // Free inodes count
+	uint32_t first_data_block; // First Data Block
+	uint32_t log_block_size; // Block size
+	uint32_t obso_log_frag_size; // Obsoleted fragment size
+	uint32_t blocks_per_group; // Number of blocks per group
+	uint32_t obso_frags_per_group; // Obsoleted fragments per group
+	uint32_t inodes_per_group; // Number of inodes per group
+	uint32_t mount_time; // Mount time
+	uint32_t write_time; // Write time
+	uint16_t mount_count; // Mount count
+	uint16_t max_mount_count; // Maximal mount count
+	uint16_t magic; // Magic signature
+	uint16_t state; // File system state
+	uint16_t errors; // Behaviour when detecting errors
+	uint16_t minor_rev_level; // Minor revision level
+	uint32_t last_check_time; // Time of last check
+	uint32_t check_interval; // Maximum time between checks
+	uint32_t creator_os; // Creator OS
+	uint32_t rev_level; // Revision level
+	uint16_t def_resuid; // Default uid for reserved blocks
+	uint16_t def_resgid; // Default gid for reserved blocks
+
+	// Fields for EXT4_DYNAMIC_REV superblocks only.
+	uint32_t first_inode; // First non-reserved inode
+	uint16_t inode_size; // Size of inode structure
+	uint16_t block_group_number; // Block group number of this superblock
+	uint32_t features_compatible; // Compatible feature set
+	uint32_t features_incompatible; // Incompatible feature set
+	uint32_t features_read_only; // Readonly-compatible feature set
+	uint8_t uuid[16]; // 128-bit uuid for volume
+	char volume_name[16]; // Volume name
+	char last_mounted[64]; // Directory where last mounted
+	uint32_t algorithm_usage_bitmap; // For compression
+
+	/*
+	 * Performance hints. Directory preallocation should only
+	 * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
+	 */
+	uint8_t s_prealloc_blocks; // Number of blocks to try to preallocate
+	uint8_t s_prealloc_dir_blocks; // Number to preallocate for dirs
+	uint16_t s_reserved_gdt_blocks; // Per group desc for online growth
+
+	/*
+	 * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
+	 */
+	uint8_t journal_uuid[16]; // UUID of journal superblock
+	uint32_t journal_inode_number; // Inode number of journal file
+	uint32_t journal_dev; // Device number of journal file
+	uint32_t last_orphan; // Head of list of inodes to delete
+	uint32_t hash_seed[4]; // HTREE hash seed
+	uint8_t default_hash_version; // Default hash version to use
+	uint8_t journal_backup_type;
+	uint16_t desc_size; // Size of group descriptor
+	uint32_t default_mount_opts; // Default mount options
+	uint32_t first_meta_bg; // First metablock block group
+	uint32_t mkfs_time; // When the filesystem was created
+	uint32_t journal_blocks[17]; // Backup of the journal inode
+
+	/* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
+	uint32_t blocks_count_hi; // Blocks count
+	uint32_t reserved_blocks_count_hi; // Reserved blocks count
+	uint32_t free_blocks_count_hi; // Free blocks count
+	uint16_t min_extra_isize; // All inodes have at least # bytes
+	uint16_t want_extra_isize; // New inodes should reserve # bytes
+	uint32_t lags; // Miscellaneous flags
+	uint16_t raid_stride; // RAID stride
+	uint16_t mmp_interval; // # seconds to wait in MMP checking
+	uint64_t mmp_block; // Block for multi-mount protection
+	uint32_t raid_stripe_width; // blocks on all data disks (N*stride)
+	uint8_t log_groups_per_flex; // FLEX_BG group size
+	uint8_t reserved_char_pad;
+	uint16_t reserved_pad;
+	uint64_t kbytes_written; // Number of lifetime kilobytes written
+	uint32_t snapshot_inum; // Inode number of active snapshot
+	uint32_t snapshot_id; // Sequential ID of active snapshot
+	uint64_t snapshot_r_blocks_count; /* reserved blocks for active snapshot's future use */
+	uint32_t snapshot_list; // inode number of the head of the on-disk snapshot list
+	uint32_t error_count; // number of fs errors
+	uint32_t first_error_time; // First time an error happened
+	uint32_t first_error_ino; // Inode involved in first error
+	uint64_t first_error_block; // block involved of first error
+	uint8_t first_error_func[32]; // Function where the error happened
+	uint32_t first_error_line; // Line number where error happened
+	uint32_t last_error_time; // Most recent time of an error
+	uint32_t last_error_ino; // Inode involved in last error
+	uint32_t last_error_line; // Line number where error happened
+	uint64_t last_error_block;     // Block involved of last error
+	uint8_t last_error_func[32];  // Function where the error happened
+	uint8_t mount_opts[64];
+	uint32_t padding[112]; // Padding to the end of the block
+} __attribute__((packed)) ext4_superblock_t;
+
+#define EXT4_SUPERBLOCK_MAGIC		0xEF53
+#define EXT4_SUPERBLOCK_SIZE		1024
+#define EXT4_SUPERBLOCK_OFFSET		1024
+
+#define EXT4_SUPERBLOCK_OS_LINUX	0
+#define EXT4_SUPERBLOCK_OS_HURD		1
+
+extern uint32_t ext4_superblock_get_inodes_count(ext4_superblock_t *);
+extern uint64_t ext4_superblock_get_blocks_count(ext4_superblock_t *);
+extern uint64_t ext4_superblock_get_reserved_blocks_count(ext4_superblock_t *);
+extern uint64_t ext4_superblock_get_free_blocks_count(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_free_inodes_count(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_first_data_block(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_log_block_size(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_block_size(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_blocks_per_group(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_mount_time(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_write_time(ext4_superblock_t *);
+extern uint16_t ext4_superblock_get_mount_count(ext4_superblock_t *);
+extern uint16_t ext4_superblock_get_max_mount_count(ext4_superblock_t *);
+extern uint16_t ext4_superblock_get_magic(ext4_superblock_t *);
+extern uint16_t ext4_superblock_get_state(ext4_superblock_t *);
+extern uint16_t ext4_superblock_get_errors(ext4_superblock_t *);
+extern uint16_t ext4_superblock_get_minor_rev_level(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_last_check_time(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_check_interval(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_creator_os(ext4_superblock_t *);
+extern uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *);
+
+/*
+uint16_t s_def_resuid; // Default uid for reserved blocks
+uint16_t s_def_resgid; // Default gid for reserved blocks
+*/
+
+extern uint32_t ext4_superblock_get_first_inode(ext4_superblock_t *);
+extern uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *);
+extern uint16_t ext4_superblock_get_block_group_number(ext4_superblock_t *);
+extern uint32_t	ext4_superblock_get_features_compatible(ext4_superblock_t *);
+extern uint32_t	ext4_superblock_get_features_incompatible(ext4_superblock_t *);
+extern uint32_t	ext4_superblock_get_features_read_only(ext4_superblock_t *);
+
+/*
+uint8_t s_uuid[16]; // 128-bit uuid for volume
+char volume_name[16]; // Volume name
+char last_mounted[64]; // Directory where last mounted
+uint32_t s_algorithm_usage_bitmap; // For compression
+uint8_t s_prealloc_blocks; // Number of blocks to try to preallocate
+uint8_t s_prealloc_dir_blocks; // Number to preallocate for dirs
+uint16_t s_reserved_gdt_blocks; // Per group desc for online growth
+uint8_t s_journal_uuid[16]; // UUID of journal superblock
+uint32_t s_journal_inum; // Inode number of journal file
+uint32_t s_journal_dev; // Device number of journal file
+uint32_t s_last_orphan; // Head of list of inodes to delete
+uint32_t s_hash_seed[4]; // HTREE hash seed
+uint8_t s_def_hash_version; // Default hash version to use
+uint8_t s_jnl_backup_type;
+uint16_t s_desc_size; // Size of group descriptor
+uint32_t s_default_mount_opts; // Default mount options
+uint32_t s_first_meta_bg; // First metablock block group
+uint32_t s_mkfs_time; // When the filesystem was created
+uint32_t s_jnl_blocks[17]; // Backup of the journal inode
+uint16_t s_min_extra_isize; // All inodes have at least # bytes
+uint16_t s_want_extra_isize; // New inodes should reserve # bytes
+uint32_t s_flags; // Miscellaneous flags
+uint16_t s_raid_stride; // RAID stride
+uint16_t s_mmp_interval; // # seconds to wait in MMP checking
+uint64_t s_mmp_block; // Block for multi-mount protection
+uint32_t s_raid_stripe_width; // blocks on all data disks (N*stride)
+uint8_t s_log_groups_per_flex; // FLEX_BG group size
+uint8_t s_reserved_char_pad;
+uint16_t s_reserved_pad;
+uint64_t s_kbytes_written; // Number of lifetime kilobytes written
+uint32_t s_snapshot_inum; // Inode number of active snapshot
+uint32_t s_snapshot_id; // Sequential ID of active snapshot
+uint64_t s_snapshot_r_blocks_count; // reserved blocks for active snapshot's future use
+uint32_t s_snapshot_list; // inode number of the head of the on-disk snapshot list
+uint32_t s_error_count; // number of fs errors
+uint32_t s_first_error_time; // First time an error happened
+uint32_t s_first_error_ino; // Inode involved in first error
+uint64_t s_first_error_block; // block involved of first error
+uint8_t s_first_error_func[32]; // Function where the error happened
+uint32_t s_first_error_line; // Line number where error happened
+uint32_t s_last_error_time; // Most recent time of an error
+uint32_t s_last_error_ino; // Inode involved in last error
+uint32_t s_last_error_line; // Line number where error happened
+uint64_t s_last_error_block;     // block involved of last error
+uint8_t s_last_error_func[32];  // function where the error happened
+uint8_t s_mount_opts[64];
+*/
+
+/* More complex superblock functions */
+extern int ext4_superblock_read_direct(service_id_t, ext4_superblock_t **);
+extern int ext4_superblock_check_sanity(ext4_superblock_t *);
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/srv/fs/ext4fs/Makefile
===================================================================
--- uspace/srv/fs/ext4fs/Makefile	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/srv/fs/ext4fs/Makefile	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2011 Frantisek Princ
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../../..
+LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBFS_PREFIX)/libfs.a $(LIBEXT4_PREFIX)/libext4.a
+EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX) -I$(LIBEXT4_PREFIX)
+BINARY = ext4fs
+
+SOURCES = \
+	ext4fs.c \
+	ext4fs_ops.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/fs/ext4fs/ext4fs.c
===================================================================
--- uspace/srv/fs/ext4fs/ext4fs.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/srv/fs/ext4fs/ext4fs.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup fs
+ * @{
+ */ 
+
+/**
+ * @file	ext4fs.c
+ * @brief	EXT4 file system driver for HelenOS.
+ */
+
+#include <async.h>
+#include <errno.h>
+#include <libfs.h>
+#include <ns.h>
+#include <stdio.h>
+#include <task.h>
+#include <ipc/services.h>
+#include "ext4fs.h"
+#include "../../vfs/vfs.h"
+
+#define NAME	"ext4fs"
+
+vfs_info_t ext4fs_vfs_info = {
+	.name = NAME,
+	.instance = 0,
+};
+
+int main(int argc, char **argv)
+{
+	printf(NAME ": HelenOS EXT4 file system server\n");
+
+	if (argc == 3) {
+		if (!str_cmp(argv[1], "--instance"))
+			ext4fs_vfs_info.instance = strtol(argv[2], NULL, 10);
+		else {
+			printf(NAME " Unrecognized parameters");
+			return -1;
+		}
+	}
+
+	async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
+		SERVICE_VFS, 0, 0);
+	if (!vfs_sess) {
+		printf(NAME ": failed to connect to VFS\n");
+		return -1;
+	}
+
+	int rc = ext4fs_global_init();
+	if (rc != EOK) {
+		printf(NAME ": Failed global initialization\n");
+		return 1;
+	}
+
+	rc = fs_register(vfs_sess, &ext4fs_vfs_info, &ext4fs_ops,
+	    &ext4fs_libfs_ops);
+	if (rc != EOK) {
+		fprintf(stdout, NAME ": Failed to register fs (%d)\n", rc);
+		return 1;
+	}
+
+	printf(NAME ": Accepting connections\n");
+	task_retval(0);
+	async_manager();
+	/* not reached */
+	return 0;
+}
+
+/**
+ * @}
+ */ 
Index: uspace/srv/fs/ext4fs/ext4fs.h
===================================================================
--- uspace/srv/fs/ext4fs/ext4fs.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/srv/fs/ext4fs/ext4fs.h	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup fs
+ * @{
+ */ 
+
+#ifndef EXT4FS_EXT4FS_H_
+#define EXT4FS_EXT4FS_H_
+
+#include <libfs.h>
+
+extern vfs_out_ops_t ext4fs_ops;
+extern libfs_ops_t ext4fs_libfs_ops;
+
+extern int ext4fs_global_init(void);
+extern int ext4fs_global_fini(void);
+
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/srv/fs/ext4fs/ext4fs_ops.c
===================================================================
--- uspace/srv/fs/ext4fs/ext4fs_ops.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
+++ uspace/srv/fs/ext4fs/ext4fs_ops.c	(revision 22ceff3a80ac18ff36c3836ced4e7fe4470aca56)
@@ -0,0 +1,966 @@
+/*
+ * Copyright (c) 2011 Frantisek Princ
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup fs
+ * @{
+ */ 
+
+/**
+ * @file	ext4fs_ops.c
+ * @brief	VFS operations for EXT4 filesystem.
+ */
+
+#include <errno.h>
+#include <fibril_synch.h>
+#include <libext4.h>
+#include <libfs.h>
+#include <macros.h>
+#include <malloc.h>
+#include <adt/hash_table.h>
+#include <ipc/loc.h>
+#include "ext4fs.h"
+#include "../../vfs/vfs.h"
+
+#define EXT4FS_NODE(node)	((node) ? (ext4fs_node_t *) (node)->data : NULL)
+
+#define OPEN_NODES_KEYS 2
+#define OPEN_NODES_DEV_HANDLE_KEY 0
+#define OPEN_NODES_INODE_KEY 1
+#define OPEN_NODES_BUCKETS 256
+
+typedef struct ext4fs_instance {
+	link_t link;
+	service_id_t service_id;
+	ext4_filesystem_t *filesystem;
+	unsigned int open_nodes_count;
+} ext4fs_instance_t;
+
+typedef struct ext4fs_node {
+	ext4fs_instance_t *instance;
+	ext4_inode_ref_t *inode_ref;
+	fs_node_t *fs_node;
+	link_t link;
+	unsigned int references;
+} ext4fs_node_t;
+
+/*
+ * Forward declarations of auxiliary functions
+ */
+
+static int ext4fs_read_directory(ipc_callid_t, aoff64_t, size_t,
+    ext4fs_instance_t *, ext4_inode_ref_t *, size_t *);
+static int ext4fs_read_file(ipc_callid_t, aoff64_t, size_t, ext4fs_instance_t *,
+    ext4_inode_ref_t *, size_t *);
+static bool ext4fs_is_dots(const uint8_t *, size_t);
+static int ext4fs_instance_get(service_id_t, ext4fs_instance_t **);
+static int ext4fs_node_get_core(fs_node_t **, ext4fs_instance_t *, fs_index_t);
+static int ext4fs_node_put_core(ext4fs_node_t *);
+
+/*
+ * Forward declarations of EXT4 libfs operations.
+ */
+static int ext4fs_root_get(fs_node_t **, service_id_t);
+static int ext4fs_match(fs_node_t **, fs_node_t *, const char *);
+static int ext4fs_node_get(fs_node_t **, service_id_t, fs_index_t);
+static int ext4fs_node_open(fs_node_t *);
+static int ext4fs_node_put(fs_node_t *);
+static int ext4fs_create_node(fs_node_t **, service_id_t, int);
+static int ext4fs_destroy_node(fs_node_t *);
+static int ext4fs_link(fs_node_t *, fs_node_t *, const char *);
+static int ext4fs_unlink(fs_node_t *, fs_node_t *, const char *);
+static int ext4fs_has_children(bool *, fs_node_t *);
+static fs_index_t ext4fs_index_get(fs_node_t *);
+static aoff64_t ext4fs_size_get(fs_node_t *);
+static unsigned ext4fs_lnkcnt_get(fs_node_t *);
+static bool ext4fs_is_directory(fs_node_t *);
+static bool ext4fs_is_file(fs_node_t *node);
+static service_id_t ext4fs_service_get(fs_node_t *node);
+
+/*
+ * Static variables
+ */
+static LIST_INITIALIZE(instance_list);
+static FIBRIL_MUTEX_INITIALIZE(instance_list_mutex);
+static hash_table_t open_nodes;
+static FIBRIL_MUTEX_INITIALIZE(open_nodes_lock);
+
+/* Hash table interface for open nodes hash table */
+static hash_index_t open_nodes_hash(unsigned long key[])
+{
+	/* TODO: This is very simple and probably can be improved */
+	return key[OPEN_NODES_INODE_KEY] % OPEN_NODES_BUCKETS;
+}
+
+static int open_nodes_compare(unsigned long key[], hash_count_t keys,
+    link_t *item)
+{
+	ext4fs_node_t *enode = hash_table_get_instance(item, ext4fs_node_t, link);
+	assert(keys > 0);
+	if (enode->instance->service_id !=
+	    ((service_id_t) key[OPEN_NODES_DEV_HANDLE_KEY])) {
+		return false;
+	}
+	if (keys == 1) {
+		return true;
+	}
+	assert(keys == 2);
+	return (enode->inode_ref->index == key[OPEN_NODES_INODE_KEY]);
+}
+
+static void open_nodes_remove_cb(link_t *link)
+{
+	/* We don't use remove callback for this hash table */
+}
+
+static hash_table_operations_t open_nodes_ops = {
+	.hash = open_nodes_hash,
+	.compare = open_nodes_compare,
+	.remove_callback = open_nodes_remove_cb,
+};
+
+
+int ext4fs_global_init(void)
+{
+	if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS,
+	    OPEN_NODES_KEYS, &open_nodes_ops)) {
+		return ENOMEM;
+	}
+	return EOK;
+}
+
+
+int ext4fs_global_fini(void)
+{
+	hash_table_destroy(&open_nodes);
+	return EOK;
+}
+
+
+/*
+ * EXT4 libfs operations.
+ */
+
+int ext4fs_instance_get(service_id_t service_id, ext4fs_instance_t **inst)
+{
+	ext4fs_instance_t *tmp;
+
+	fibril_mutex_lock(&instance_list_mutex);
+
+	if (list_empty(&instance_list)) {
+		fibril_mutex_unlock(&instance_list_mutex);
+		return EINVAL;
+	}
+
+	list_foreach(instance_list, link) {
+		tmp = list_get_instance(link, ext4fs_instance_t, link);
+
+		if (tmp->service_id == service_id) {
+			*inst = tmp;
+			fibril_mutex_unlock(&instance_list_mutex);
+			return EOK;
+		}
+	}
+
+	fibril_mutex_unlock(&instance_list_mutex);
+	return EINVAL;
+}
+
+
+int ext4fs_root_get(fs_node_t **rfn, service_id_t service_id)
+{
+	return ext4fs_node_get(rfn, service_id, EXT4_INODE_ROOT_INDEX);
+}
+
+
+int ext4fs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
+{
+	ext4fs_node_t *eparent = EXT4FS_NODE(pfn);
+	ext4_filesystem_t *fs;
+	ext4_directory_iterator_t it;
+	int rc;
+	size_t name_size;
+	size_t component_size;
+	bool found = false;
+	uint32_t inode;
+
+	fs = eparent->instance->filesystem;
+
+	if (!ext4_inode_is_type(fs->superblock, eparent->inode_ref->inode,
+	    EXT4_INODE_MODE_DIRECTORY)) {
+		return ENOTDIR;
+	}
+
+	rc = ext4_directory_iterator_init(&it, fs, eparent->inode_ref, 0);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	/* Find length of component in bytes
+	 * TODO: check for library function call that does this
+	 */
+	component_size = 0;
+	while (*(component+component_size) != 0) {
+		component_size++;
+	}
+
+	while (it.current != NULL) {
+		inode = ext4_directory_entry_ll_get_inode(it.current);
+
+		/* ignore empty directory entries */
+		if (inode != 0) {
+			name_size = ext4_directory_entry_ll_get_name_length(fs->superblock,
+				it.current);
+
+			if (name_size == component_size && bcmp(component, &it.current->name,
+				    name_size) == 0) {
+				rc = ext4fs_node_get_core(rfn, eparent->instance,
+					inode);
+				if (rc != EOK) {
+					ext4_directory_iterator_fini(&it);
+					return rc;
+				}
+				found = true;
+				break;
+			}
+		}
+
+		rc = ext4_directory_iterator_next(&it);
+		if (rc != EOK) {
+			ext4_directory_iterator_fini(&it);
+			return rc;
+		}
+	}
+
+	ext4_directory_iterator_fini(&it);
+
+	if (!found) {
+		return ENOENT;
+	}
+
+	return EOK;
+}
+
+
+int ext4fs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index)
+{
+	ext4fs_instance_t *inst = NULL;
+	int rc;
+
+	rc = ext4fs_instance_get(service_id, &inst);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	return ext4fs_node_get_core(rfn, inst, index);
+}
+
+
+int ext4fs_node_get_core(fs_node_t **rfn, ext4fs_instance_t *inst,
+		fs_index_t index)
+{
+	int rc;
+	fs_node_t *node = NULL;
+	ext4fs_node_t *enode = NULL;
+
+	ext4_inode_ref_t *inode_ref = NULL;
+
+	fibril_mutex_lock(&open_nodes_lock);
+
+	/* Check if the node is not already open */
+	unsigned long key[] = {
+		[OPEN_NODES_DEV_HANDLE_KEY] = inst->service_id,
+		[OPEN_NODES_INODE_KEY] = index,
+	};
+	link_t *already_open = hash_table_find(&open_nodes, key);
+
+	if (already_open) {
+		enode = hash_table_get_instance(already_open, ext4fs_node_t, link);
+		*rfn = enode->fs_node;
+		enode->references++;
+
+		fibril_mutex_unlock(&open_nodes_lock);
+		return EOK;
+	}
+
+	enode = malloc(sizeof(ext4fs_node_t));
+	if (enode == NULL) {
+		fibril_mutex_unlock(&open_nodes_lock);
+		return ENOMEM;
+	}
+
+	node = malloc(sizeof(fs_node_t));
+	if (node == NULL) {
+		free(enode);
+		fibril_mutex_unlock(&open_nodes_lock);
+		return ENOMEM;
+	}
+	fs_node_initialize(node);
+
+	rc = ext4_filesystem_get_inode_ref(inst->filesystem, index, &inode_ref);
+	if (rc != EOK) {
+		free(enode);
+		free(node);
+		fibril_mutex_unlock(&open_nodes_lock);
+		return rc;
+	}
+
+	enode->inode_ref = inode_ref;
+	enode->instance = inst;
+	enode->references = 1;
+	enode->fs_node = node;
+	link_initialize(&enode->link);
+
+	node->data = enode;
+	*rfn = node;
+
+	hash_table_insert(&open_nodes, key, &enode->link);
+	inst->open_nodes_count++;
+
+	fibril_mutex_unlock(&open_nodes_lock);
+
+	return EOK;
+}
+
+
+int ext4fs_node_put_core(ext4fs_node_t *enode)
+{
+	int rc;
+	unsigned long key[] = {
+		[OPEN_NODES_DEV_HANDLE_KEY] = enode->instance->service_id,
+		[OPEN_NODES_INODE_KEY] = enode->inode_ref->index,
+	};
+
+	hash_table_remove(&open_nodes, key, OPEN_NODES_KEYS);
+	assert(enode->instance->open_nodes_count > 0);
+	enode->instance->open_nodes_count--;
+
+	rc = ext4_filesystem_put_inode_ref(enode->inode_ref);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	free(enode->fs_node);
+	free(enode);
+
+	return EOK;
+}
+
+
+int ext4fs_node_open(fs_node_t *fn)
+{
+	// TODO stateless operation
+	return EOK;
+}
+
+int ext4fs_node_put(fs_node_t *fn)
+{
+	int rc;
+	ext4fs_node_t *enode = EXT4FS_NODE(fn);
+
+	fibril_mutex_lock(&open_nodes_lock);
+
+	assert(enode->references > 0);
+	enode->references--;
+	if (enode->references == 0) {
+		rc = ext4fs_node_put_core(enode);
+		if (rc != EOK) {
+			fibril_mutex_unlock(&open_nodes_lock);
+			return rc;
+		}
+	}
+
+	fibril_mutex_unlock(&open_nodes_lock);
+
+	return EOK;
+}
+
+
+int ext4fs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
+{
+	EXT4FS_DBG("not supported");
+
+	// TODO
+	return ENOTSUP;
+}
+
+
+int ext4fs_destroy_node(fs_node_t *fn)
+{
+	EXT4FS_DBG("not supported");
+
+	// TODO
+	return ENOTSUP;
+}
+
+
+int ext4fs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
+{
+	EXT4FS_DBG("not supported");
+
+	// TODO
+	return ENOTSUP;
+}
+
+
+int ext4fs_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
+{
+	EXT4FS_DBG("not supported");
+
+	// TODO
+	return ENOTSUP;
+}
+
+
+int ext4fs_has_children(bool *has_children, fs_node_t *fn)
+{
+	ext4fs_node_t *enode = EXT4FS_NODE(fn);
+	ext4_directory_iterator_t it;
+	ext4_filesystem_t *fs;
+	int rc;
+	bool found = false;
+	size_t name_size;
+
+	fs = enode->instance->filesystem;
+
+	if (!ext4_inode_is_type(fs->superblock, enode->inode_ref->inode,
+	    EXT4_INODE_MODE_DIRECTORY)) {
+		*has_children = false;
+		return EOK;
+	}
+
+	rc = ext4_directory_iterator_init(&it, fs, enode->inode_ref, 0);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	/* Find a non-empty directory entry */
+	while (it.current != NULL) {
+		if (it.current->inode != 0) {
+			name_size = ext4_directory_entry_ll_get_name_length(fs->superblock,
+				it.current);
+			if (!ext4fs_is_dots(it.current->name, name_size)) {
+				found = true;
+				break;
+			}
+		}
+
+		rc = ext4_directory_iterator_next(&it);
+		if (rc != EOK) {
+			ext4_directory_iterator_fini(&it);
+			return rc;
+		}
+	}
+
+	rc = ext4_directory_iterator_fini(&it);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	*has_children = found;
+
+	return EOK;
+}
+
+
+fs_index_t ext4fs_index_get(fs_node_t *fn)
+{
+	ext4fs_node_t *enode = EXT4FS_NODE(fn);
+	return enode->inode_ref->index;
+}
+
+
+aoff64_t ext4fs_size_get(fs_node_t *fn)
+{
+	ext4fs_node_t *enode = EXT4FS_NODE(fn);
+	aoff64_t size = ext4_inode_get_size(enode->instance->filesystem->superblock,
+	    enode->inode_ref->inode);
+	return size;
+}
+
+
+unsigned ext4fs_lnkcnt_get(fs_node_t *fn)
+{
+	ext4fs_node_t *enode = EXT4FS_NODE(fn);
+	unsigned count = ext4_inode_get_links_count(enode->inode_ref->inode);
+	return count;
+}
+
+
+bool ext4fs_is_directory(fs_node_t *fn)
+{
+	ext4fs_node_t *enode = EXT4FS_NODE(fn);
+	bool is_dir = ext4_inode_is_type(enode->instance->filesystem->superblock,
+	    enode->inode_ref->inode, EXT4_INODE_MODE_DIRECTORY);
+	return is_dir;
+}
+
+
+bool ext4fs_is_file(fs_node_t *fn)
+{
+	ext4fs_node_t *enode = EXT4FS_NODE(fn);
+	bool is_file = ext4_inode_is_type(enode->instance->filesystem->superblock,
+	    enode->inode_ref->inode, EXT4_INODE_MODE_FILE);
+	return is_file;
+}
+
+
+service_id_t ext4fs_service_get(fs_node_t *fn)
+{
+	ext4fs_node_t *enode = EXT4FS_NODE(fn);
+	return enode->instance->service_id;
+}
+
+/*
+ * libfs operations.
+ */
+libfs_ops_t ext4fs_libfs_ops = {
+	.root_get = ext4fs_root_get,
+	.match = ext4fs_match,
+	.node_get = ext4fs_node_get,
+	.node_open = ext4fs_node_open,
+	.node_put = ext4fs_node_put,
+	.create = ext4fs_create_node,
+	.destroy = ext4fs_destroy_node,
+	.link = ext4fs_link,
+	.unlink = ext4fs_unlink,
+	.has_children = ext4fs_has_children,
+	.index_get = ext4fs_index_get,
+	.size_get = ext4fs_size_get,
+	.lnkcnt_get = ext4fs_lnkcnt_get,
+	.is_directory = ext4fs_is_directory,
+	.is_file = ext4fs_is_file,
+	.service_get = ext4fs_service_get
+};
+
+
+/*
+ * VFS operations.
+ */
+
+static int ext4fs_mounted(service_id_t service_id, const char *opts,
+   fs_index_t *index, aoff64_t *size, unsigned *lnkcnt)
+{
+	int rc;
+	ext4_filesystem_t *fs;
+	ext4fs_instance_t *inst;
+	bool read_only;
+
+	/* Allocate libext4 filesystem structure */
+	fs = (ext4_filesystem_t *) malloc(sizeof(ext4_filesystem_t));
+	if (fs == NULL) {
+		return ENOMEM;
+	}
+
+	/* Allocate instance structure */
+	inst = (ext4fs_instance_t *) malloc(sizeof(ext4fs_instance_t));
+	if (inst == NULL) {
+		free(fs);
+		return ENOMEM;
+	}
+
+	/* Initialize the filesystem */
+	rc = ext4_filesystem_init(fs, service_id);
+	if (rc != EOK) {
+		free(fs);
+		free(inst);
+		return rc;
+	}
+
+	/* Do some sanity checking */
+	rc = ext4_filesystem_check_sanity(fs);
+	if (rc != EOK) {
+		ext4_filesystem_fini(fs);
+		free(fs);
+		free(inst);
+		return rc;
+	}
+
+	/* Check flags */
+	rc = ext4_filesystem_check_features(fs, &read_only);
+	if (rc != EOK) {
+		ext4_filesystem_fini(fs);
+		free(fs);
+		free(inst);
+		return rc;
+	}
+
+	/* Initialize instance */
+	link_initialize(&inst->link);
+	inst->service_id = service_id;
+	inst->filesystem = fs;
+	inst->open_nodes_count = 0;
+
+	/* Read root node */
+	fs_node_t *root_node;
+	rc = ext4fs_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX);
+	if (rc != EOK) {
+		ext4_filesystem_fini(fs);
+		free(fs);
+		free(inst);
+		return rc;
+	}
+	ext4fs_node_t *enode = EXT4FS_NODE(root_node);
+
+	/* Add instance to the list */
+	fibril_mutex_lock(&instance_list_mutex);
+	list_append(&inst->link, &instance_list);
+	fibril_mutex_unlock(&instance_list_mutex);
+
+	*index = EXT4_INODE_ROOT_INDEX;
+	*size = 0;
+	*lnkcnt = ext4_inode_get_links_count(enode->inode_ref->inode);
+
+	ext4fs_node_put(root_node);
+
+	return EOK;
+}
+
+
+static int ext4fs_unmounted(service_id_t service_id)
+{
+	int rc;
+	ext4fs_instance_t *inst;
+
+	rc = ext4fs_instance_get(service_id, &inst);
+
+	if (rc != EOK) {
+		return rc;
+	}
+
+	fibril_mutex_lock(&open_nodes_lock);
+
+	if (inst->open_nodes_count != 0) {
+		fibril_mutex_unlock(&open_nodes_lock);
+		return EBUSY;
+	}
+
+	/* Remove the instance from the list */
+	fibril_mutex_lock(&instance_list_mutex);
+	list_remove(&inst->link);
+	fibril_mutex_unlock(&instance_list_mutex);
+
+	fibril_mutex_unlock(&open_nodes_lock);
+
+	ext4_filesystem_fini(inst->filesystem);
+
+	return EOK;
+}
+
+
+static int
+ext4fs_read(service_id_t service_id, fs_index_t index, aoff64_t pos,
+    size_t *rbytes)
+{
+	ext4fs_instance_t *inst;
+	ext4_inode_ref_t *inode_ref;
+	int rc;
+
+	/*
+	 * Receive the read request.
+	 */
+	ipc_callid_t callid;
+	size_t size;
+	if (!async_data_read_receive(&callid, &size)) {
+		async_answer_0(callid, EINVAL);
+		return EINVAL;
+	}
+
+	rc = ext4fs_instance_get(service_id, &inst);
+	if (rc != EOK) {
+		async_answer_0(callid, rc);
+		return rc;
+	}
+
+	rc = ext4_filesystem_get_inode_ref(inst->filesystem, index, &inode_ref);
+	if (rc != EOK) {
+		async_answer_0(callid, rc);
+		return rc;
+	}
+
+	if (ext4_inode_is_type(inst->filesystem->superblock, inode_ref->inode,
+			EXT4_INODE_MODE_FILE)) {
+		rc = ext4fs_read_file(callid, pos, size, inst, inode_ref,
+				rbytes);
+	} else if (ext4_inode_is_type(inst->filesystem->superblock,
+			inode_ref->inode, EXT4_INODE_MODE_DIRECTORY)) {
+		rc = ext4fs_read_directory(callid, pos, size, inst, inode_ref,
+				rbytes);
+	} else {
+		/* Other inode types not supported */
+		async_answer_0(callid, ENOTSUP);
+		rc = ENOTSUP;
+	}
+
+	ext4_filesystem_put_inode_ref(inode_ref);
+
+	return rc;
+}
+
+bool ext4fs_is_dots(const uint8_t *name, size_t name_size)
+{
+	if (name_size == 1 && name[0] == '.') {
+		return true;
+	}
+
+	if (name_size == 2 && name[0] == '.' && name[1] == '.') {
+		return true;
+	}
+
+	return false;
+}
+
+int ext4fs_read_directory(ipc_callid_t callid, aoff64_t pos, size_t size,
+    ext4fs_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes)
+{
+
+	ext4_directory_iterator_t it;
+	aoff64_t next;
+	uint8_t *buf;
+	size_t name_size;
+	int rc;
+	bool found = false;
+
+	// TODO check if directory uses HTree
+	if (ext4_inode_has_flag(inode_ref->inode, EXT4_INODE_FLAG_INDEX)) {
+		EXT4FS_DBG("Directory using HTree");
+	}
+
+	rc = ext4_directory_iterator_init(&it, inst->filesystem, inode_ref, pos);
+	if (rc != EOK) {
+		async_answer_0(callid, rc);
+		return rc;
+	}
+
+	/* Find next interesting directory entry.
+	 * We want to skip . and .. entries
+	 * as these are not used in HelenOS
+	 */
+	while (it.current != NULL) {
+
+		if (it.current->inode == 0) {
+			goto skip;
+		}
+
+		name_size = ext4_directory_entry_ll_get_name_length(
+		    inst->filesystem->superblock, it.current);
+
+		/* skip . and .. */
+		if (ext4fs_is_dots(it.current->name, name_size)) {
+			goto skip;
+		}
+
+		/* The on-disk entry does not contain \0 at the end
+		 * end of entry name, so we copy it to new buffer
+		 * and add the \0 at the end
+		 */
+		buf = malloc(name_size+1);
+		if (buf == NULL) {
+			ext4_directory_iterator_fini(&it);
+			async_answer_0(callid, ENOMEM);
+			return ENOMEM;
+		}
+		memcpy(buf, &it.current->name, name_size);
+		*(buf + name_size) = 0;
+		found = true;
+		(void) async_data_read_finalize(callid, buf, name_size + 1);
+		free(buf);
+		break;
+
+skip:
+		rc = ext4_directory_iterator_next(&it);
+		if (rc != EOK) {
+			ext4_directory_iterator_fini(&it);
+			async_answer_0(callid, rc);
+			return rc;
+		}
+	}
+
+	if (found) {
+		rc = ext4_directory_iterator_next(&it);
+		if (rc != EOK) {
+			return rc;
+		}
+		next = it.current_offset;
+	}
+
+	rc = ext4_directory_iterator_fini(&it);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	if (found) {
+		*rbytes = next - pos;
+		return EOK;
+	} else {
+		async_answer_0(callid, ENOENT);
+		return ENOENT;
+	}
+}
+
+int ext4fs_read_file(ipc_callid_t callid, aoff64_t pos, size_t size,
+    ext4fs_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes)
+{
+	int rc;
+	uint32_t block_size;
+	aoff64_t file_block;
+	uint64_t file_size;
+	uint32_t fs_block;
+	size_t offset_in_block;
+	size_t bytes;
+	block_t *block;
+	uint8_t *buffer;
+
+	file_size = ext4_inode_get_size(inst->filesystem->superblock,
+		inode_ref->inode);
+
+	if (pos >= file_size) {
+		/* Read 0 bytes successfully */
+		async_data_read_finalize(callid, NULL, 0);
+		*rbytes = 0;
+		return EOK;
+	}
+
+	/* For now, we only read data from one block at a time */
+	block_size = ext4_superblock_get_block_size(inst->filesystem->superblock);
+	file_block = pos / block_size;
+	offset_in_block = pos % block_size;
+	bytes = min(block_size - offset_in_block, size);
+
+	/* Handle end of file */
+	if (pos + bytes > file_size) {
+		bytes = file_size - pos;
+	}
+
+	/* Get the real block number */
+	rc = ext4_filesystem_get_inode_data_block_index(inst->filesystem,
+		inode_ref->inode, file_block, &fs_block);
+	if (rc != EOK) {
+		async_answer_0(callid, rc);
+		return rc;
+	}
+
+	/* Check for sparse file
+	 * If ext2_filesystem_get_inode_data_block_index returned
+	 * fs_block == 0, it means that the given block is not allocated for the
+	 * file and we need to return a buffer of zeros
+	 */
+	if (fs_block == 0) {
+		buffer = malloc(bytes);
+		if (buffer == NULL) {
+			async_answer_0(callid, ENOMEM);
+			return ENOMEM;
+		}
+
+		memset(buffer, 0, bytes);
+
+		async_data_read_finalize(callid, buffer, bytes);
+		*rbytes = bytes;
+
+		free(buffer);
+
+		return EOK;
+	}
+
+	/* Usual case - we need to read a block from device */
+	rc = block_get(&block, inst->service_id, fs_block, BLOCK_FLAGS_NONE);
+	if (rc != EOK) {
+		async_answer_0(callid, rc);
+		return rc;
+	}
+
+	assert(offset_in_block + bytes <= block_size);
+	async_data_read_finalize(callid, block->data + offset_in_block, bytes);
+
+	rc = block_put(block);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	*rbytes = bytes;
+	return EOK;
+}
+
+static int
+ext4fs_write(service_id_t service_id, fs_index_t index, aoff64_t pos,
+    size_t *wbytes, aoff64_t *nsize)
+{
+	EXT4FS_DBG("not supported");
+
+	// TODO
+	return ENOTSUP;
+}
+
+
+static int
+ext4fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t size)
+{
+	EXT4FS_DBG("not supported");
+
+	// TODO
+	return ENOTSUP;
+}
+
+
+static int ext4fs_close(service_id_t service_id, fs_index_t index)
+{
+	// TODO
+	return EOK;
+}
+
+
+static int ext4fs_destroy(service_id_t service_id, fs_index_t index)
+{
+	EXT4FS_DBG("not supported");
+
+	//TODO
+	return ENOTSUP;
+}
+
+
+static int ext4fs_sync(service_id_t service_id, fs_index_t index)
+{
+	EXT4FS_DBG("not supported");
+
+	// TODO
+	return ENOTSUP;
+}
+
+vfs_out_ops_t ext4fs_ops = {
+	.mounted = ext4fs_mounted,
+	.unmounted = ext4fs_unmounted,
+	.read = ext4fs_read,
+	.write = ext4fs_write,
+	.truncate = ext4fs_truncate,
+	.close = ext4fs_close,
+	.destroy = ext4fs_destroy,
+	.sync = ext4fs_sync,
+};
+
+/**
+ * @}
+ */ 
