Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ uspace/Makefile	(revision fa4b7ba3bcacc85590ded951cca73d17aa733b08)
@@ -40,5 +40,4 @@
 	app/devctl \
 	app/edit \
-	app/ext2info \
 	app/getterm \
 	app/init \
@@ -105,5 +104,4 @@
 	srv/fs/mfs \
 	srv/fs/locfs \
-	srv/fs/ext2fs \
 	srv/fs/ext4fs \
 	srv/hid/compositor \
@@ -213,5 +211,4 @@
 	lib/net \
 	lib/nic \
-	lib/ext2 \
 	lib/ext4 \
 	lib/usb \
Index: uspace/app/ext2info/Makefile
===================================================================
--- uspace/app/ext2info/Makefile	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,38 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# 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 $(LIBEXT2_PREFIX)/libext2.a
-EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBEXT2_PREFIX)
-BINARY = ext2info
-
-SOURCES = \
-	ext2info.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/ext2info/ext2info.c
===================================================================
--- uspace/app/ext2info/ext2info.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,624 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * Copyright (c) 2010 Jiri Svoboda
- * 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	ext2info.c
- * @brief	Tool for displaying information about ext2 filesystem
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <block.h>
-#include <mem.h>
-#include <loc.h>
-#include <byteorder.h>
-#include <sys/types.h>
-#include <sys/typefmt.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <libext2.h>
-#include <assert.h>
-
-#define NAME	"ext2info"
-
-static void syntax_print(void);
-static void print_superblock(ext2_superblock_t *);
-static void print_block_groups(ext2_filesystem_t *);
-static void print_block_group(ext2_block_group_t *);
-static void print_inode_by_number(ext2_filesystem_t *, uint32_t, bool, uint32_t,
-    bool, bool);
-static void print_data(unsigned char *, size_t);
-static void print_inode(ext2_filesystem_t *, ext2_inode_t *, bool);
-static void print_inode_data(ext2_filesystem_t *, ext2_inode_t *, uint32_t);
-static void print_directory_contents(ext2_filesystem_t *, ext2_inode_ref_t *);
-
-#define ARG_SUPERBLOCK 1
-#define ARG_BLOCK_GROUPS 2
-#define ARG_INODE 4
-#define ARG_NO_CHECK 8
-#define ARG_INODE_DATA 16
-#define ARG_INODE_LIST 32
-#define ARG_INODE_BLOCKS 64
-#define ARG_COMMON (ARG_SUPERBLOCK)
-#define ARG_ALL 127
-
-
-int main(int argc, char **argv)
-{
-
-	int rc;
-	char *endptr;
-	char *dev_path;
-	service_id_t service_id;
-	ext2_filesystem_t filesystem;
-	int arg_flags;
-	uint32_t inode = 0;
-	uint32_t inode_data = 0;
-	
-	arg_flags = 0;
-	
-	if (argc < 2) {
-		printf(NAME ": Error, argument missing.\n");
-		syntax_print();
-		return 1;
-	}
-	
-	/* Skip program name */
-	--argc; ++argv;
-	
-	if (argc > 0 && str_cmp(*argv, "--no-check") == 0) {
-		--argc; ++argv;
-		arg_flags |= ARG_NO_CHECK;
-	}
-	
-	if (argc > 0 && str_cmp(*argv, "--superblock") == 0) {
-		--argc; ++argv;
-		arg_flags |= ARG_SUPERBLOCK;
-	}
-	
-	if (argc > 0 && str_cmp(*argv, "--block-groups") == 0) {
-		--argc; ++argv;
-		arg_flags |= ARG_BLOCK_GROUPS;
-	}
-	
-	if (argc > 0 && str_cmp(*argv, "--inode") == 0) {
-		--argc; ++argv;
-		if (argc == 0) {
-			printf(NAME ": Argument expected for --inode\n");
-			return 2;
-		}
-		
-		inode = strtol(*argv, &endptr, 10);
-		if (*endptr != '\0') {
-			printf(NAME ": Error, invalid argument for --inode.\n");
-			syntax_print();
-			return 1;
-		}
-		
-		arg_flags |= ARG_INODE;
-		--argc; ++argv;
-		
-		if (argc > 0 && str_cmp(*argv, "--blocks") == 0) {
-			--argc; ++argv;
-			arg_flags |= ARG_INODE_BLOCKS;
-		}
-		
-		if (argc > 0 && str_cmp(*argv, "--data") == 0) {
-			--argc; ++argv;
-			if (argc == 0) {
-				printf(NAME ": Argument expected for --data\n");
-				return 2;
-			}
-			
-			inode_data = strtol(*argv, &endptr, 10);
-			if (*endptr != '\0') {
-				printf(NAME ": Error, invalid argument for --data.\n");
-				syntax_print();
-				return 1;
-			}
-			
-			arg_flags |= ARG_INODE_DATA;
-			--argc; ++argv;
-		}
-		
-		if (argc > 0 && str_cmp(*argv, "--list") == 0) {
-			--argc; ++argv;
-			arg_flags |= ARG_INODE_LIST;
-		}
-	}
-
-	if (argc < 1) {
-		printf(NAME ": Error, argument missing.\n");
-		syntax_print();
-		return 1;
-	}
-	else if (argc > 1) {
-		printf(NAME ": Error, unexpected argument.\n");
-		syntax_print();
-		return 1;
-	}
-	assert(argc == 1);
-	
-	/* Display common things by default */
-	if ((arg_flags & ARG_ALL) == 0) {
-		arg_flags = ARG_COMMON;
-	}
-
-	dev_path = *argv;
-
-	rc = loc_service_get_id(dev_path, &service_id, 0);
-	if (rc != EOK) {
-		printf(NAME ": Error resolving device `%s'.\n", dev_path);
-		return 2;
-	}
-
-	rc = ext2_filesystem_init(&filesystem, service_id);
-	if (rc != EOK)  {
-		printf(NAME ": Error initializing libext2.\n");
-		return 3;
-	}
-	
-	rc = ext2_filesystem_check_sanity(&filesystem);
-	if (rc != EOK) {
-		printf(NAME ": Filesystem did not pass sanity check.\n");
-		if (!(arg_flags & ARG_NO_CHECK)) {
-			return 3;
-		}
-	}
-	
-	if (arg_flags & ARG_SUPERBLOCK) {
-		print_superblock(filesystem.superblock);
-	}
-	
-	if (arg_flags & ARG_BLOCK_GROUPS) {
-		print_block_groups(&filesystem);
-	}
-	
-	if (arg_flags & ARG_INODE) {
-		print_inode_by_number(&filesystem, inode, arg_flags & ARG_INODE_DATA,
-		    inode_data, arg_flags & ARG_INODE_LIST,
-		    arg_flags & ARG_INODE_BLOCKS);
-	}
-
-	ext2_filesystem_fini(&filesystem);
-
-	return 0;
-}
-
-
-static void syntax_print(void)
-{
-	printf("syntax: ext2info [--no-check] [--superblock] [--block-groups] "
-	    "[--inode <i-number> [--blocks] [--data <block-number>] [--list]] "
-	    "<device_name>\n");
-}
-
-static void print_superblock(ext2_superblock_t *superblock)
-{
-	uint16_t magic;
-	uint32_t first_block;
-	uint32_t block_size;
-	uint32_t fragment_size;
-	uint32_t blocks_per_group;
-	uint32_t fragments_per_group;
-	uint32_t rev_major;
-	uint16_t rev_minor;
-	uint16_t state;
-	uint32_t first_inode;
-	uint16_t inode_size;
-	uint32_t total_blocks;
-	uint32_t reserved_blocks;
-	uint32_t free_blocks;
-	uint32_t total_inodes;
-	uint32_t free_inodes;	
-	uint32_t os;
-	
-	int pos;
-	unsigned char c;
-	
-	magic = ext2_superblock_get_magic(superblock);
-	first_block = ext2_superblock_get_first_block(superblock);
-	block_size = ext2_superblock_get_block_size(superblock);
-	fragment_size = ext2_superblock_get_fragment_size(superblock);
-	blocks_per_group = ext2_superblock_get_blocks_per_group(superblock);
-	fragments_per_group = ext2_superblock_get_fragments_per_group(superblock);
-	rev_major = ext2_superblock_get_rev_major(superblock);
-	rev_minor = ext2_superblock_get_rev_minor(superblock);
-	state = ext2_superblock_get_state(superblock);
-	first_inode = ext2_superblock_get_first_inode(superblock);
-	inode_size = ext2_superblock_get_inode_size(superblock);
-	total_blocks = ext2_superblock_get_total_block_count(superblock);
-	reserved_blocks = ext2_superblock_get_reserved_block_count(superblock);
-	free_blocks = ext2_superblock_get_free_block_count(superblock);
-	total_inodes = ext2_superblock_get_total_inode_count(superblock);
-	free_inodes = ext2_superblock_get_free_inode_count(superblock);
-	os = ext2_superblock_get_os(superblock);
-	
-	printf("Superblock:\n");
-	
-	if (magic == EXT2_SUPERBLOCK_MAGIC) {
-		printf("  Magic value: %X (correct)\n", magic);
-	}
-	else {
-		printf("  Magic value: %X (incorrect)\n", magic);
-	}
-	
-	printf("  Revision: %u.%hu\n", rev_major, rev_minor);
-	printf("  State: %hu\n", state);
-	printf("  Creator OS: %u\n", os);
-	printf("  First block: %u\n", first_block);
-	printf("  Block size: %u bytes (%u KiB)\n", block_size, block_size/1024);
-	printf("  Blocks per group: %u\n", blocks_per_group);
-	printf("  Total blocks: %u\n", total_blocks);
-	printf("  Reserved blocks: %u\n", reserved_blocks);
-	printf("  Free blocks: %u\n", free_blocks);
-	printf("  Fragment size: %u bytes (%u KiB)\n", fragment_size,
-	    fragment_size/1024);
-	printf("  Fragments per group: %u\n", fragments_per_group);
-	printf("  First inode: %u\n", first_inode);
-	printf("  Inode size: %hu bytes\n", inode_size);
-	printf("  Total inodes: %u\n", total_inodes);
-	printf("  Free inodes: %u\n", free_inodes);
-	
-	
-	if (rev_major == 1) {
-		printf("  UUID: ");
-		for (pos = 0; pos < 16; pos++) {
-			printf("%02x", superblock->uuid[pos]);
-		}
-		printf("\n");
-		
-		printf("  Volume label: ");
-		for (pos = 0; pos < 16; pos++) {
-			c = superblock->volume_name[pos];
-			if (c >= 32 && c < 128) {
-				putchar(c);
-			}
-			else {
-				putchar(' ');
-			}
-		}
-		printf("\n");
-	}
-	
-}
-
-void print_block_groups(ext2_filesystem_t *filesystem)
-{
-	uint32_t block_group_count;
-	uint32_t i;
-	ext2_block_group_ref_t *block_group_ref;
-	int rc;
-	
-	printf("Block groups:\n");
-	
-	block_group_count = ext2_superblock_get_block_group_count(
-	    filesystem->superblock);
-	
-	for (i = 0; i < block_group_count; i++) {
-		printf("  Block group %u\n", i);
-		rc = ext2_filesystem_get_block_group_ref(filesystem, i, &block_group_ref);
-		if (rc != EOK) {
-			printf("    Failed reading block group\n");
-			continue;
-		}
-		
-		print_block_group(block_group_ref->block_group);
-		
-		rc = ext2_filesystem_put_block_group_ref(block_group_ref);
-		if (rc != EOK) {
-			printf("    Failed freeing block group\n");
-		}
-	}
-	
-}
-
-void print_block_group(ext2_block_group_t *bg)
-{
-	uint32_t block_bitmap_block;
-	uint32_t inode_bitmap_block;
-	uint32_t inode_table_first_block;
-	uint16_t free_block_count;
-	uint16_t free_inode_count;
-	uint16_t directory_inode_count;
-	
-	block_bitmap_block = ext2_block_group_get_block_bitmap_block(bg);
-	inode_bitmap_block = ext2_block_group_get_inode_bitmap_block(bg);
-	inode_table_first_block = ext2_block_group_get_inode_table_first_block(bg);
-	free_block_count = ext2_block_group_get_free_block_count(bg);
-	free_inode_count = ext2_block_group_get_free_inode_count(bg);
-	directory_inode_count = ext2_block_group_get_directory_inode_count(bg);
-	
-	printf("    Block bitmap block: %u\n", block_bitmap_block);
-	printf("    Inode bitmap block: %u\n", inode_bitmap_block);
-	printf("    Inode table's first block: %u\n", inode_table_first_block);
-	printf("    Free blocks: %u\n", free_block_count);
-	printf("    Free inodes: %u\n", free_inode_count);
-	printf("    Directory inodes: %u\n", directory_inode_count);
-}
-
-void print_inode_by_number(ext2_filesystem_t *fs, uint32_t inode, 
-    bool print_data, uint32_t data, bool list, bool blocks)
-{
-	int rc;
-	ext2_inode_ref_t *inode_ref;
-	
-	printf("Inode %u\n", inode);
-	
-	rc = ext2_filesystem_get_inode_ref(fs, inode, &inode_ref);
-	if (rc != EOK) {
-		printf("  Failed getting inode ref\n");
-		return;
-	}
-	
-	print_inode(fs, inode_ref->inode, blocks);
-	if (print_data) {
-		print_inode_data(fs, inode_ref->inode, data);
-	}
-	
-	if (list && ext2_inode_is_type(fs->superblock, inode_ref->inode,
-	    EXT2_INODE_MODE_DIRECTORY)) {
-		print_directory_contents(fs, inode_ref);
-	}
-	
-	rc = ext2_filesystem_put_inode_ref(inode_ref);
-	if (rc != EOK) {
-		printf("  Failed putting inode ref\n");
-	}
-}
-
-void print_inode(ext2_filesystem_t *fs, ext2_inode_t *inode, bool blocks)
-{
-	uint32_t mode;
-	uint32_t mode_type;
-	uint32_t user_id;
-	uint32_t group_id;
-	uint64_t size;
-	uint16_t usage_count;
-	uint32_t flags;
-	uint16_t access;
-	const char *type;
-	uint32_t total_blocks;
-	uint32_t i;
-	uint32_t range_start;
-	uint32_t range_last;
-	uint32_t range_start_file;
-	uint32_t range_last_file;
-	uint32_t range_current;
-	uint32_t range_expected;
-	uint32_t block_size;
-	uint64_t file_blocks;
-	bool printed_range;
-	int rc;
-	
-	block_size = ext2_superblock_get_block_size(fs->superblock);
-	mode = ext2_inode_get_mode(fs->superblock, inode);
-	mode_type = mode & EXT2_INODE_MODE_TYPE_MASK;
-	user_id = ext2_inode_get_user_id(fs->superblock, inode);
-	group_id = ext2_inode_get_group_id(fs->superblock, inode);
-	size = ext2_inode_get_size(fs->superblock, inode);
-	usage_count = ext2_inode_get_usage_count(inode);
-	flags = ext2_inode_get_flags(inode);
-	total_blocks = ext2_inode_get_reserved_blocks(fs->superblock, inode);
-	file_blocks = 0;
-	if (size > 0) {
-		file_blocks = ((size-1)/block_size)+1;
-	}
-	
-	type = "Unknown";
-	if (mode_type == EXT2_INODE_MODE_BLOCKDEV) {
-		type = "Block device";
-	}
-	else if (mode_type == EXT2_INODE_MODE_FIFO) {
-		type = "Fifo (pipe)";
-	}
-	else if (mode_type == EXT2_INODE_MODE_CHARDEV) {
-		type = "Character device";
-	}
-	else if (mode_type == EXT2_INODE_MODE_DIRECTORY) {
-		type = "Directory";
-	}
-	else if (mode_type == EXT2_INODE_MODE_FILE) {
-		type = "File";
-	}
-	else if (mode_type == EXT2_INODE_MODE_SOFTLINK) {
-		type = "Soft link";
-	}
-	else if (mode_type == EXT2_INODE_MODE_SOCKET) {
-		type = "Socket";
-	}
-	
-	access = mode & EXT2_INODE_MODE_ACCESS_MASK;
-	
-	
-	printf("  Mode: %08x (Type: %s, Access bits: %04ho)\n", mode, type, access);
-	printf("  User ID: %u\n", user_id);
-	printf("  Group ID: %u\n", group_id);
-	printf("  Size: %" PRIu64 "\n", size);
-	printf("  Usage (link) count: %u\n", usage_count);
-	printf("  Flags: %u\n", flags);
-	printf("  Total allocated blocks: %u\n", total_blocks);
-	
-	if (blocks) {
-		printf("  Block list: ");
-		
-		range_start = 0;
-		range_current = 0;
-		range_last = 0;
-		
-		printed_range = false;
-		
-		for (i = 0; i <= file_blocks; i++) {
-			if (i < file_blocks) {
-				rc = ext2_filesystem_get_inode_data_block_index(fs, inode, i, &range_current);
-				if (rc != EOK) {
-					printf("Error reading data block indexes\n");
-					return;
-				}
-			}
-			if (range_last == 0) {
-				range_expected = 0;
-			}
-			else {
-				range_expected = range_last + 1;
-			}
-			if (range_current != range_expected) {
-				if (i > 0) {
-					if (printed_range) {
-						printf(", ");
-					}
-					if (range_start == 0 && range_last == 0) {
-						if (range_start_file == range_last_file) {
-							printf("%u N/A", range_start_file);
-						}
-						else {
-							printf("[%u, %u] N/A", range_start_file,
-								range_last_file);
-						}
-					}
-					else {
-						if (range_start_file == range_last_file) {
-							printf("%u -> %u", range_start_file, range_start);
-						}
-						else {
-							printf("[%u, %u] -> [%u, %u]", range_start_file,
-								range_last_file, range_start, range_last);
-						}
-					}
-					printed_range = true;
-				}
-				range_start = range_current;
-				range_start_file = i;
-			}
-			range_last = range_current;
-			range_last_file = i;
-		}
-		printf("\n");
-	}
-}
-
-void print_data(unsigned char *data, size_t size)
-{
-	unsigned char c;
-	size_t i;
-	
-	for (i = 0; i < size; i++) {
-		c = data[i];
-		if (c >= 32 && c < 127) {
-			putchar(c);
-		}
-		else {
-			putchar('.');
-		}
-	}
-}
-
-void print_inode_data(ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t data)
-{
-	int rc;
-	uint32_t data_block_index;
-	block_t *block;
-	
-	rc = ext2_filesystem_get_inode_data_block_index(fs, inode, data,
-	    &data_block_index);
-	
-	if (rc != EOK) {
-		printf("Failed getting data block #%u\n", data);
-		return;
-	}
-	
-	printf("Data for inode contents block #%u is located in filesystem "
-	    "block %u\n", data, data_block_index);
-	
-	printf("Data preview (only printable characters):\n");
-	
-	rc = block_get(&block, fs->device, data_block_index, 0);
-	if (rc != EOK) {
-		printf("Failed reading filesystem block %u\n", data_block_index);
-		return;
-	}
-	
-	print_data(block->data, block->size);
-	printf("\n");	
-	
-	rc = block_put(block);
-	if (rc != EOK) {
-		printf("Failed putting filesystem block\n");
-	}
-	
-}
-
-void print_directory_contents(ext2_filesystem_t *fs,
-    ext2_inode_ref_t *inode_ref)
-{
-	int rc;
-	ext2_directory_iterator_t it;
-	size_t name_size;
-	uint32_t inode;
-	
-	printf("  Directory contents:\n");
-	
-	rc = ext2_directory_iterator_init(&it, fs, inode_ref, 0);
-	if (rc != EOK) {
-		printf("Failed initializing directory iterator\n");
-		return;
-	}
-	
-	while (it.current != NULL) {
-		name_size = ext2_directory_entry_ll_get_name_length(fs->superblock,
-		    it.current);
-		printf("    ");
-		print_data(&it.current->name, name_size);
-		
-		inode = ext2_directory_entry_ll_get_inode(it.current);
-		printf(" --> %u\n", inode);
-		
-		rc = ext2_directory_iterator_next(&it);
-		if (rc != EOK) {
-			printf("Failed reading directory contents\n");
-			goto cleanup;
-		}
-	}
-
-cleanup:
-	rc = ext2_directory_iterator_fini(&it);
-	if (rc != EOK) {
-		printf("Failed cleaning-up directory iterator\n");
-	}
-	
-}
-
-/**
- * @}
- */
Index: uspace/app/tester/Makefile
===================================================================
--- uspace/app/tester/Makefile	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ uspace/app/tester/Makefile	(revision fa4b7ba3bcacc85590ded951cca73d17aa733b08)
@@ -29,6 +29,6 @@
 
 USPACE_PREFIX = ../..
-LIBS = $(LIBEXT2_PREFIX)/libext2.a $(LIBBLOCK_PREFIX)/libblock.a $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
-EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBEXT2_PREFIX) -I$(LIBSOFTFLOAT_PREFIX)
+LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a
+EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX) -I$(LIBSOFTFLOAT_PREFIX)
 BINARY = tester
 
@@ -63,6 +63,5 @@
 	mm/mapping1.c \
 	hw/misc/virtchar1.c \
-	hw/serial/serial1.c \
-	ext2/ext2_1.c
+	hw/serial/serial1.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/app/tester/ext2/ext2_1.c
===================================================================
--- uspace/app/tester/ext2/ext2_1.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,106 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include "../tester.h"
-#include "../util.h"
-#include <libext2.h>
-#include <malloc.h>
-
-static ext2_superblock_t *fake_superblock1()
-{
-	uint8_t *buf;
-	int i;
-	
-	buf = malloc(EXT2_SUPERBLOCK_SIZE);
-	if (buf == NULL) {
-		return NULL;
-	}
-	
-	for (i = 0; i < EXT2_SUPERBLOCK_SIZE; i++) {
-		buf[i] = i % 256;
-	}
-	
-	return (ext2_superblock_t *) buf;
-}
-
-const char *test_ext2_1(void)
-{
-	ext2_superblock_t *fake1;
-	
-	TPRINTF("Testing ext2 superblock getters...\n");
-	TPRINTF("Simple test for correct position and byte order\n");
-	
-	fake1 = fake_superblock1();
-	if (fake1 == NULL) {
-		return "Failed allocating memory for test superblock 1";
-	}
-	
-	ASSERT_EQ_32(0x03020100, ext2_superblock_get_total_inode_count(fake1),
-	    "Failed getting total inode count");
-	ASSERT_EQ_32(0x07060504, ext2_superblock_get_total_block_count(fake1),
-	    "Failed getting total block count");
-	ASSERT_EQ_32(0x0B0A0908, ext2_superblock_get_reserved_block_count(fake1),
-	    "Failed getting reserved block count");
-	ASSERT_EQ_32(0x0F0E0D0C, ext2_superblock_get_free_block_count(fake1),
-	    "Failed getting free block count");
-	ASSERT_EQ_32(0x13121110, ext2_superblock_get_free_inode_count(fake1),
-	    "Failed getting free inode count");
-	ASSERT_EQ_32(0x17161514, ext2_superblock_get_first_block(fake1),
-	    "Failed getting first block number");
-	ASSERT_EQ_32(0x1B1A1918, ext2_superblock_get_block_size_log2(fake1),
-	    "Failed getting log block size");
-	ASSERT_EQ_32(0x1F1E1D1C, ext2_superblock_get_fragment_size_log2(fake1),
-	    "Failed getting log fragment size");
-	ASSERT_EQ_32(0x23222120, ext2_superblock_get_blocks_per_group(fake1),
-	    "Failed getting blocks per group");
-	ASSERT_EQ_32(0x27262524, ext2_superblock_get_fragments_per_group(fake1),
-	    "Failed getting fragments per group");
-	ASSERT_EQ_32(0x2B2A2928, ext2_superblock_get_inodes_per_group(fake1),
-	    "Failed getting inodes per group");
-	ASSERT_EQ_16(0x3938, ext2_superblock_get_magic(fake1),
-	    "Failed getting magic number");
-	ASSERT_EQ_16(0x3B3A, ext2_superblock_get_state(fake1),
-	    "Failed getting state");
-	ASSERT_EQ_16(0x3F3E, ext2_superblock_get_rev_minor(fake1),
-	    "Failed getting minor revision number");
-	ASSERT_EQ_32(0x4B4A4948, ext2_superblock_get_os(fake1),
-	    "Failed getting OS");
-	ASSERT_EQ_32(0x4F4E4D4C, ext2_superblock_get_rev_major(fake1),
-	    "Failed getting major revision number");
-	ASSERT_EQ_32(0x57565554, ext2_superblock_get_first_inode(fake1),
-	    "Failed getting first inode number");
-	ASSERT_EQ_16(0x5958, ext2_superblock_get_inode_size(fake1),
-	    "Failed getting size");
-	ASSERT_EQ_8(0x68, fake1->uuid[0], "UUID position is incorrect");
-	ASSERT_EQ_8(0x78, fake1->volume_name[0],
-	    "Volume name position is incorrect");
-	
-	return NULL;
-}
Index: uspace/app/tester/ext2/ext2_1.def
===================================================================
--- uspace/app/tester/ext2/ext2_1.def	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,6 +1,0 @@
-{
-	"ext2_1",
-	"Superblock getters test",
-	&test_ext2_1,
-	true
-},
Index: uspace/app/tester/tester.c
===================================================================
--- uspace/app/tester/tester.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ uspace/app/tester/tester.c	(revision fa4b7ba3bcacc85590ded951cca73d17aa733b08)
@@ -74,5 +74,4 @@
 #include "hw/serial/serial1.def"
 #include "hw/misc/virtchar1.def"
-#include "ext2/ext2_1.def"
 	{NULL, NULL, NULL, false}
 };
Index: uspace/lib/ext2/Makefile
===================================================================
--- uspace/lib/ext2/Makefile	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,43 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# Copyright (c) 2010 Martin Sucha
-# 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 = libext2
-EXTRA_CFLAGS = -I$(LIBBLOCK_PREFIX)
-LIBS = $(LIBBLOCK_PREFIX)/libblock.a
-
-SOURCES = \
-	libext2_filesystem.c \
-	libext2_superblock.c \
-	libext2_block_group.c \
-	libext2_inode.c \
-	libext2_directory.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/ext2/libext2.h
===================================================================
--- uspace/lib/ext2/libext2.h	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#ifndef LIBEXT2_LIBEXT2_H_
-#define LIBEXT2_LIBEXT2_H_
-
-#include "libext2_superblock.h"
-#include "libext2_block_group.h"
-#include "libext2_inode.h"
-#include "libext2_filesystem.h"
-#include "libext2_directory.h"
-
-#endif
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_block_group.c
===================================================================
--- uspace/lib/ext2/libext2_block_group.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,114 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#include "libext2.h"
-#include "libext2_block_group.h"
-#include <byteorder.h>
-
-/**
- * Get block ID corresponding to the block bitmap of this block group
- * 
- * @param bg pointer to block group descriptor
- */
-uint32_t ext2_block_group_get_block_bitmap_block(ext2_block_group_t *bg)
-{
-	return uint32_t_le2host(bg->block_bitmap_block);
-}
-
-/**
- * Get block ID corresponding to the inode bitmap of this block group
- * 
- * @param bg pointer to block group descriptor
- */
-uint32_t ext2_block_group_get_inode_bitmap_block(ext2_block_group_t *bg)
-{
-	return uint32_t_le2host(bg->inode_bitmap_block);
-}
-
-/**
- * Get block ID of first block in inode table
- * 
- * @param bg pointer to block group descriptor
- */
-uint32_t ext2_block_group_get_inode_table_first_block(ext2_block_group_t *bg)
-{
-	return uint32_t_le2host(bg->inode_table_first_block);
-}
-
-/**
- * Get amount of free blocks in this block group
- * 
- * @param bg pointer to block group descriptor
- */
-uint16_t ext2_block_group_get_free_block_count(ext2_block_group_t *bg)
-{
-	return uint16_t_le2host(bg->free_block_count);
-}
-
-/**
- * Set amount of free blocks in this block group
- * 
- * @param bg pointer to block group descriptor
- * @param val new value
- */
-void ext2_block_group_set_free_block_count(ext2_block_group_t *bg,
-	uint16_t val)
-{
-	bg->free_block_count = host2uint16_t_le(val);
-}
-
-/**
- * Get amount of free inodes in this block group
- * 
- * @param bg pointer to block group descriptor
- */
-uint16_t ext2_block_group_get_free_inode_count(ext2_block_group_t *bg)
-{
-	return uint16_t_le2host(bg->free_inode_count);
-}
-
-/**
- * Get amount of inodes allocated for directories
- * 
- * @param bg pointer to block group descriptor
- */
-uint16_t ext2_block_group_get_directory_inode_count(ext2_block_group_t *bg)
-{
-	return uint16_t_le2host(bg->directory_inode_count);
-}
-
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_block_group.h
===================================================================
--- uspace/lib/ext2/libext2_block_group.h	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,69 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#ifndef LIBEXT2_LIBEXT2_BLOCK_GROUP_H_
-#define LIBEXT2_LIBEXT2_BLOCK_GROUP_H_
-
-#include <block.h>
-
-typedef struct ext2_block_group {
-	uint32_t block_bitmap_block; // Block ID for block bitmap
-	uint32_t inode_bitmap_block; // Block ID for inode bitmap
-	uint32_t inode_table_first_block; // Block ID of first block of inode table 
-	uint16_t free_block_count; // Count of free blocks
-	uint16_t free_inode_count; // Count of free inodes
-	uint16_t directory_inode_count; // Number of inodes allocated to directories
-} ext2_block_group_t;
-
-typedef struct ext2_block_group_ref {
-	block_t *block; // Reference to a block containing this block group descr
-	ext2_block_group_t *block_group;
-} ext2_block_group_ref_t;
-
-#define EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE 32
-
-extern uint32_t	ext2_block_group_get_block_bitmap_block(ext2_block_group_t *);
-extern uint32_t	ext2_block_group_get_inode_bitmap_block(ext2_block_group_t *);
-extern uint32_t	ext2_block_group_get_inode_table_first_block(ext2_block_group_t *);
-extern uint16_t	ext2_block_group_get_free_block_count(ext2_block_group_t *);
-extern uint16_t	ext2_block_group_get_free_inode_count(ext2_block_group_t *);
-extern uint16_t	ext2_block_group_get_directory_inode_count(ext2_block_group_t *);
-
-extern void	ext2_block_group_set_free_block_count(ext2_block_group_t *, uint16_t);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_directory.c
===================================================================
--- uspace/lib/ext2/libext2_directory.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,256 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#include "libext2.h"
-#include "libext2_directory.h"
-#include <byteorder.h>
-#include <errno.h>
-#include <assert.h>
-
-static int ext2_directory_iterator_set(ext2_directory_iterator_t *it,
-    uint32_t block_size);
-
-/**
- * Get inode number for the directory entry
- * 
- * @param de pointer to linked list directory entry
- */
-uint32_t ext2_directory_entry_ll_get_inode(ext2_directory_entry_ll_t *de)
-{
-	return uint32_t_le2host(de->inode);
-}
-
-/**
- * Get length of the directory entry
- * 
- * @param de pointer to linked list directory entry
- */
-uint16_t ext2_directory_entry_ll_get_entry_length(
-    ext2_directory_entry_ll_t *de)
-{
-	return uint16_t_le2host(de->entry_length);
-}
-
-/**
- * Get length of the name stored in the directory entry
- * 
- * @param de pointer to linked list directory entry
- */
-uint16_t ext2_directory_entry_ll_get_name_length(
-    ext2_superblock_t *sb, ext2_directory_entry_ll_t *de)
-{
-	if (ext2_superblock_get_rev_major(sb) == 0 &&
-	    ext2_superblock_get_rev_minor(sb) < 5) {
-		return ((uint16_t)de->name_length_high) << 8 | 
-		    ((uint16_t)de->name_length);
-	}
-	return de->name_length;
-}
-
-/**
- * Initialize a directory iterator
- * 
- * @param it pointer to iterator to initialize
- * @param fs pointer to filesystem structure
- * @param inode pointer to inode reference structure
- * @param pos position within inode to start at, 0 is the first entry
- * @return EOK on success or negative error code on failure
- */
-int ext2_directory_iterator_init(ext2_directory_iterator_t *it,
-    ext2_filesystem_t *fs, ext2_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 ext2_directory_iterator_seek(it, pos);
-}
-
-/**
- * Advance the directory iterator to the next entry
- * 
- * @param it pointer to iterator to initialize
- * @return EOK on success or negative error code on failure
- */
-int ext2_directory_iterator_next(ext2_directory_iterator_t *it)
-{
-	uint16_t skip;
-	
-	assert(it->current != NULL);
-	
-	skip = ext2_directory_entry_ll_get_entry_length(it->current);
-	
-	return ext2_directory_iterator_seek(it, it->current_offset + skip);
-}
-
-/**
- * Seek the directory iterator to the given byte offset within the inode.
- * 
- * @param it pointer to iterator to initialize
- * @return EOK on success or negative error code on failure
- */
-int ext2_directory_iterator_seek(ext2_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 = ext2_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 = ext2_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 = ext2_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 ext2_directory_iterator_set(it, block_size);
-}
-
-/** Setup the entry at the current iterator offset.
- * 
- * This function checks the validity of the directory entry,
- * before setting the data pointer.
- *
- * @return EOK on success or error code on failure 
- */
-static int ext2_directory_iterator_set(ext2_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;
-	}
-	
-	ext2_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 = ext2_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 (ext2_directory_entry_ll_get_name_length(it->fs->superblock, 
-	    entry) > length-8) {
-		return EIO;
-	}
-	
-	it->current = entry;
-	return EOK;
-}
-
-/**
- * Release all resources asociated with the directory iterator
- * 
- * @param it pointer to iterator to initialize
- * @return EOK on success or negative error code on failure
- */
-int ext2_directory_iterator_fini(ext2_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/ext2/libext2_directory.h
===================================================================
--- uspace/lib/ext2/libext2_directory.h	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,81 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#ifndef LIBEXT2_LIBEXT2_DIRECTORY_H_
-#define LIBEXT2_LIBEXT2_DIRECTORY_H_
-
-#include <block.h>
-#include "libext2_filesystem.h"
-#include "libext2_inode.h"
-
-/**
- * Linked list directory entry structure
- */
-typedef struct ext2_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; // First byte of name, if present
-} __attribute__ ((packed)) ext2_directory_entry_ll_t;
-
-typedef struct ext2_directory_iterator {
-	ext2_filesystem_t *fs;
-	ext2_inode_ref_t *inode_ref;
-	block_t *current_block;
-	aoff64_t current_offset;
-	ext2_directory_entry_ll_t *current;
-} ext2_directory_iterator_t;
-
-
-extern uint32_t	ext2_directory_entry_ll_get_inode(ext2_directory_entry_ll_t *);
-extern uint16_t	ext2_directory_entry_ll_get_entry_length(
-    ext2_directory_entry_ll_t *);
-extern uint16_t	ext2_directory_entry_ll_get_name_length(
-    ext2_superblock_t *, ext2_directory_entry_ll_t *);
-
-extern int ext2_directory_iterator_init(ext2_directory_iterator_t *,
-    ext2_filesystem_t *, ext2_inode_ref_t *, aoff64_t);
-extern int ext2_directory_iterator_next(ext2_directory_iterator_t *);
-extern int ext2_directory_iterator_seek(ext2_directory_iterator_t *, aoff64_t pos);
-extern int ext2_directory_iterator_fini(ext2_directory_iterator_t *);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_filesystem.c
===================================================================
--- uspace/lib/ext2/libext2_filesystem.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,532 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#include "libext2_filesystem.h"
-#include "libext2_superblock.h"
-#include "libext2_block_group.h"
-#include "libext2_inode.h"
-#include <errno.h>
-#include <block.h>
-#include <malloc.h>
-#include <assert.h>
-#include <byteorder.h>
-
-/**
- * Initialize an instance of filesystem on the device.
- * This function reads superblock from the device and
- * initializes libblock cache with appropriate logical block size.
- * 
- * @param fs			Pointer to ext2_filesystem_t to initialize
- * @param service_id	Service ID of the block device
- * 
- * @return 		EOK on success or negative error code on failure
- */
-int ext2_filesystem_init(ext2_filesystem_t *fs, service_id_t service_id)
-{
-	int rc;
-	ext2_superblock_t *temp_superblock;
-	size_t block_size;
-	
-	fs->device = service_id;
-	
-	rc = block_init(EXCHANGE_SERIALIZE, fs->device, 2048);
-	if (rc != EOK) {
-		return rc;
-	}
-	
-	rc = ext2_superblock_read_direct(fs->device, &temp_superblock);
-	if (rc != EOK) {
-		block_fini(fs->device);
-		return rc;
-	}
-	
-	block_size = ext2_superblock_get_block_size(temp_superblock);
-	
-	if (block_size > EXT2_MAX_BLOCK_SIZE) {
-		block_fini(fs->device);
-		return ENOTSUP;
-	}
-	
-	rc = block_cache_init(service_id, block_size, 0, CACHE_MODE_WT);
-	if (rc != EOK) {
-		block_fini(fs->device);
-		return rc;
-	}
-	
-	fs->superblock = temp_superblock;
-	
-	return EOK; 
-}
-
-/**
- * Check filesystem for sanity
- * 
- * @param fs			Pointer to ext2_filesystem_t to check
- * @return 		EOK on success or negative error code on failure
- */
-int ext2_filesystem_check_sanity(ext2_filesystem_t *fs)
-{
-	int rc;
-	
-	rc = ext2_superblock_check_sanity(fs->superblock);
-	if (rc != EOK) {
-		return rc;
-	}
-	
-	return EOK;
-}
-
-/**
- * Check feature flags
- * 
- * @param fs Pointer to ext2_filesystem_t to check
- * @param read_only bool to set to true if the fs needs to be read-only
- * @return EOK on success or negative error code on failure
- */
-int ext2_filesystem_check_flags(ext2_filesystem_t *fs, bool *o_read_only)
-{
-	/* feature flags are present in rev 1 and later */
-	if (ext2_superblock_get_rev_major(fs->superblock) == 0) {
-		*o_read_only = false;
-		return EOK;
-	}
-	
-	uint32_t incompatible;
-	uint32_t read_only;
-	
-	incompatible = ext2_superblock_get_features_incompatible(fs->superblock);
-	read_only = ext2_superblock_get_features_read_only(fs->superblock);
-	
-	/* check whether we support all features
-	 * first unset any supported feature flags
-	 * and see whether any unspported feature remains */
-	incompatible &= ~EXT2_SUPPORTED_INCOMPATIBLE_FEATURES;
-	read_only &= ~EXT2_SUPPORTED_READ_ONLY_FEATURES;
-	
-	if (incompatible > 0) {
-		*o_read_only = true;
-		return ENOTSUP;
-	}
-	
-	if (read_only > 0) {
-		*o_read_only = true;
-	}
-	
-	return EOK;
-}
-
-/**
- * Get a reference to block descriptor
- * 
- * @param fs Pointer to filesystem information
- * @param bgid Index of block group to find
- * @param ref Pointer where to store pointer to block group reference
- * 
- * @return 		EOK on success or negative error code on failure
- */
-int ext2_filesystem_get_block_group_ref(ext2_filesystem_t *fs, uint32_t bgid,
-    ext2_block_group_ref_t **ref)
-{
-	int rc;
-	aoff64_t block_id;
-	uint32_t descriptors_per_block;
-	size_t offset;
-	ext2_block_group_ref_t *newref;
-	
-	newref = malloc(sizeof(ext2_block_group_ref_t));
-	if (newref == NULL) {
-		return ENOMEM;
-	}
-	
-	descriptors_per_block = ext2_superblock_get_block_size(fs->superblock)
-	    / EXT2_BLOCK_GROUP_DESCRIPTOR_SIZE;
-	
-	/* Block group descriptor table starts at the next block after superblock */
-	block_id = ext2_superblock_get_first_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) * EXT2_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;
-}
-
-/**
- * Free a reference to block group
- * 
- * @param ref Pointer to block group reference to free
- * 
- * @return 		EOK on success or negative error code on failure
- */
-int ext2_filesystem_put_block_group_ref(ext2_block_group_ref_t *ref)
-{
-	int rc;
-	
-	rc = block_put(ref->block);
-	free(ref);
-	
-	return rc;
-}
-
-/**
- * Get a reference to inode
- * 
- * @param fs Pointer to filesystem information
- * @param index The index number of the inode
- * @param ref Pointer where to store pointer to inode reference
- * 
- * @return 		EOK on success or negative error code on failure
- */
-int ext2_filesystem_get_inode_ref(ext2_filesystem_t *fs, uint32_t index,
-    ext2_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;
-	ext2_block_group_ref_t *bg_ref;
-	ext2_inode_ref_t *newref;
-	
-	newref = malloc(sizeof(ext2_inode_ref_t));
-	if (newref == NULL) {
-		return ENOMEM;
-	}
-	
-	inodes_per_group = ext2_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 = ext2_filesystem_get_block_group_ref(fs, block_group, &bg_ref);
-	if (rc != EOK) {
-		free(newref);
-		return rc;
-	}
-	
-	inode_table_start = ext2_block_group_get_inode_table_first_block(
-	    bg_ref->block_group);
-	
-	rc = ext2_filesystem_put_block_group_ref(bg_ref);
-	if (rc != EOK) {
-		free(newref);
-		return rc;
-	}
-
-	inode_size = ext2_superblock_get_inode_size(fs->superblock);
-	block_size = ext2_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;
-}
-
-/**
- * Free a reference to inode
- * 
- * @param ref Pointer to inode reference to free
- * 
- * @return 		EOK on success or negative error code on failure
- */
-int ext2_filesystem_put_inode_ref(ext2_inode_ref_t *ref)
-{
-	int rc;
-	
-	rc = block_put(ref->block);
-	free(ref);
-	
-	return rc;
-}
-
-/**
- * Find a filesystem block number where iblock-th data block
- * of the given inode is located.
- * 
- * @param fblock the number of filesystem block, or 0 if no such block is allocated yet
- * 
- * @return 		EOK on success or negative error code on failure
- */
-int ext2_filesystem_get_inode_data_block_index(ext2_filesystem_t *fs, ext2_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 simple case when we are dealing with direct reference */ 
-	if (iblock < EXT2_INODE_DIRECT_BLOCKS) {
-		current_block = ext2_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 = ext2_superblock_get_block_size(fs->superblock) / sizeof(uint32_t);
-	limits[0] = EXT2_INODE_DIRECT_BLOCKS;
-	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 = ext2_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;
-}
-
-/**
- * Allocate a given number of blocks and store their ids in blocks
- * 
- * @todo TODO: This function is not finished and really has never been
- *             used (and tested) yet
- * 
- * @param fs pointer to filesystem
- * @param blocks array of count uint32_t values where store block ids
- * @param count number of blocks to allocate and elements in blocks array
- * @param preferred_bg preferred block group number
- * 
- * @return 		EOK on success or negative error code on failure
- */
-int ext2_filesystem_allocate_blocks(ext2_filesystem_t *fs, uint32_t *blocks,
-    size_t count, uint32_t preferred_bg)
-{
-	uint32_t bg_count = ext2_superblock_get_block_group_count(fs->superblock);
-	uint32_t bpg = ext2_superblock_get_blocks_per_group(fs->superblock);
-	uint32_t block_size = ext2_superblock_get_block_size(fs->superblock);
-	uint32_t block_group = preferred_bg;
-	uint32_t free_blocks_sb;
-	uint32_t block_groups_left;
-	size_t idx;
-	ext2_block_group_ref_t *bg;
-	int rc;
-	uint32_t bb_block;
-	block_t *block;
-	size_t bb_idx;
-	size_t bb_bit;
-	
-	free_blocks_sb = ext2_superblock_get_free_block_count(fs->superblock);
-	
-	if (count > free_blocks_sb) {
-		return EIO;
-	}
-	
-	block_groups_left = bg_count;
-	
-	idx = 0;
-	
-	/* Read the block group descriptor */
-	rc = ext2_filesystem_get_block_group_ref(fs, block_group, &bg);
-	if (rc != EOK) {
-		goto failed;
-	}
-	
-	while (idx < count && block_groups_left > 0) {
-		uint16_t fb = ext2_block_group_get_free_block_count(bg->block_group);
-		if (fb == 0) {
-			block_group = (block_group + 1) % bg_count;
-			block_groups_left -= 1;
-			
-			rc = ext2_filesystem_put_block_group_ref(bg);
-			if (rc != EOK) {
-				goto failed;
-			}
-			
-			rc = ext2_filesystem_get_block_group_ref(fs, block_group, &bg);
-			if (rc != EOK) {
-				goto failed;
-			}
-			continue;
-		}
-		
-		/* We found a block group with free block, let's look at the block bitmap */
-		bb_block = ext2_block_group_get_block_bitmap_block(bg->block_group);
-		
-		rc = block_get(&block, fs->device, bb_block, BLOCK_FLAGS_NONE);
-		if (rc != EOK) {
-			goto failed;
-		}
-		
-		/* Use all blocks from this block group */
-		for (bb_idx = 0; bb_idx < block_size && idx < count; bb_idx++) {
-			uint8_t *data = (uint8_t *) block->data;
-			if (data[bb_idx] == 0xff) {
-				continue;
-			}
-			/* find an empty bit */
-			uint8_t mask;
-			for (mask = 1, bb_bit = 0;
-				 bb_bit < 8 && idx < count; 
-				 bb_bit++, mask = mask << 1) {
-				if ((data[bb_idx] & mask) == 0) {
-					// free block found
-					blocks[idx] = block_group * bpg + bb_idx*8 + bb_bit;
-					data[bb_idx] |= mask;
-					idx += 1;
-					fb -= 1;
-					ext2_block_group_set_free_block_count(bg->block_group, fb);
-				}
-			}
-		}
-	}
-	
-	rc = ext2_filesystem_put_block_group_ref(bg);
-	if (rc != EOK) {
-		goto failed;
-	}
-	
-	// TODO update superblock
-	
-	return EOK;
-failed:
-	// TODO deallocate already allocated blocks, if possible
-	
-	return rc;
-}
-
-/**
- * Finalize an instance of filesystem
- * 
- * @param fs Pointer to ext2_filesystem_t to finalize
- */
-void ext2_filesystem_fini(ext2_filesystem_t *fs)
-{
-	free(fs->superblock);
-	block_fini(fs->device);
-}
-
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_filesystem.h
===================================================================
--- uspace/lib/ext2/libext2_filesystem.h	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,78 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#ifndef LIBEXT2_LIBEXT2_FILESYSTEM_H_
-#define LIBEXT2_LIBEXT2_FILESYSTEM_H_
-
-#include <block.h>
-#include "libext2_superblock.h"
-#include "libext2_block_group.h"
-#include "libext2_inode.h"
-
-typedef struct ext2_filesystem {
-	service_id_t		device;
-	ext2_superblock_t *	superblock;
-} ext2_filesystem_t;
-
-// allow maximum this block size
-#define EXT2_MAX_BLOCK_SIZE			8096
-#define EXT2_REV0_FIRST_INODE		11
-#define EXT2_REV0_INODE_SIZE		128
-
-#define EXT2_FEATURE_RO_SPARSE_SUPERBLOCK	1
-#define EXT2_FEATURE_RO_LARGE_FILE			2
-#define EXT2_FEATURE_I_TYPE_IN_DIR			2
-
-#define EXT2_SUPPORTED_INCOMPATIBLE_FEATURES EXT2_FEATURE_I_TYPE_IN_DIR
-#define EXT2_SUPPORTED_READ_ONLY_FEATURES 0
-
-extern int ext2_filesystem_init(ext2_filesystem_t *, service_id_t);
-extern int ext2_filesystem_check_sanity(ext2_filesystem_t *);
-extern int ext2_filesystem_check_flags(ext2_filesystem_t *, bool *);
-extern int ext2_filesystem_get_block_group_ref(ext2_filesystem_t *, uint32_t, 
-    ext2_block_group_ref_t **);
-extern int ext2_filesystem_put_block_group_ref(ext2_block_group_ref_t *);
-extern int ext2_filesystem_get_inode_ref(ext2_filesystem_t *, uint32_t,
-    ext2_inode_ref_t **);
-extern int ext2_filesystem_put_inode_ref(ext2_inode_ref_t *);
-extern int ext2_filesystem_get_inode_data_block_index(ext2_filesystem_t *, ext2_inode_t*,
-    aoff64_t, uint32_t*);
-extern int ext2_filesystem_allocate_blocks(ext2_filesystem_t *, uint32_t *, size_t, uint32_t);
-extern void ext2_filesystem_fini(ext2_filesystem_t *);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_inode.c
===================================================================
--- uspace/lib/ext2/libext2_inode.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,192 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#include "libext2.h"
-#include "libext2_inode.h"
-#include "libext2_superblock.h"
-#include <byteorder.h>
-#include <assert.h>
-
-/**
- * Get mode stored in the inode
- * 
- * @param inode pointer to inode
- */
-uint32_t ext2_inode_get_mode(ext2_superblock_t *sb, ext2_inode_t *inode)
-{
-	if (ext2_superblock_get_os(sb) == EXT2_SUPERBLOCK_OS_HURD) {
-		return ((uint32_t)uint16_t_le2host(inode->mode_high)) << 16 |
-		    ((uint32_t)uint16_t_le2host(inode->mode));
-	}
-	return uint16_t_le2host(inode->mode);
-}
-
-/**
- * Check whether inode is of given type
- * 
- * @param sb pointer to superblock structure
- * @param inode pointer to inode
- * @param type EXT2_INODE_MODE_TYPE_* constant to check
- */
-bool ext2_inode_is_type(ext2_superblock_t *sb, ext2_inode_t *inode, uint32_t type)
-{
-	uint32_t mode = ext2_inode_get_mode(sb, inode);
-	return (mode & EXT2_INODE_MODE_TYPE_MASK) == type;
-}
-
-/**
- * Get uid this inode is belonging to
- * 
- * @param inode pointer to inode
- */
-uint32_t ext2_inode_get_user_id(ext2_superblock_t *sb, ext2_inode_t *inode)
-{
-	uint32_t os = ext2_superblock_get_os(sb);
-	if (os == EXT2_SUPERBLOCK_OS_LINUX || os == EXT2_SUPERBLOCK_OS_HURD) {
-		return ((uint32_t)uint16_t_le2host(inode->user_id_high)) << 16 |
-		    ((uint32_t)uint16_t_le2host(inode->user_id));
-	}
-	return uint16_t_le2host(inode->user_id);
-}
-
-/**
- * Get size of file
- * 
- * For regular files in revision 1 and later, the high 32 bits of
- * file size are stored in inode->size_high and are 0 otherwise
- * 
- * @param inode pointer to inode
- */
-uint64_t ext2_inode_get_size(ext2_superblock_t *sb, ext2_inode_t *inode)
-{
-	uint32_t major_rev = ext2_superblock_get_rev_major(sb);
-	
-	if (major_rev > 0 && ext2_inode_is_type(sb, inode, EXT2_INODE_MODE_FILE)) {
-		return ((uint64_t)uint32_t_le2host(inode->size_high)) << 32 |
-		    ((uint64_t)uint32_t_le2host(inode->size));
-	}
-	return uint32_t_le2host(inode->size);
-}
-
-/**
- * Get gid this inode belongs to
- * 
- * For Linux and Hurd, the high 16 bits are stored in OS dependent part
- * of inode structure
- * 
- * @param inode pointer to inode
- */
-uint32_t ext2_inode_get_group_id(ext2_superblock_t *sb, ext2_inode_t *inode)
-{
-	uint32_t os = ext2_superblock_get_os(sb);
-	if (os == EXT2_SUPERBLOCK_OS_LINUX || os == EXT2_SUPERBLOCK_OS_HURD) {
-		return ((uint32_t)uint16_t_le2host(inode->group_id_high)) << 16 |
-		    ((uint32_t)uint16_t_le2host(inode->group_id));
-	}
-	return uint16_t_le2host(inode->group_id);
-}
-
-/**
- * Get usage count (i.e. hard link count)
- * A value of 1 is common, while 0 means that the inode should be freed
- * 
- * @param inode pointer to inode
- */
-uint16_t ext2_inode_get_usage_count(ext2_inode_t *inode)
-{
-	return uint16_t_le2host(inode->usage_count);
-}
-
-/**
- * Get number of 512-byte data blocks allocated for contents of the file
- * represented by this inode.
- * This should be multiple of block size unless fragments are used.
- * 
- * @param inode pointer to inode
- */
-uint32_t ext2_inode_get_reserved_512_blocks(ext2_inode_t *inode)
-{
-	return uint32_t_le2host(inode->reserved_512_blocks);
-}
-
-/**
- * Get number of blocks allocated for contents of the file
- * represented by this inode.
- * 
- * @param inode pointer to inode
- */
-uint32_t ext2_inode_get_reserved_blocks(ext2_superblock_t *sb,
-    ext2_inode_t *inode)
-{
-	return ext2_inode_get_reserved_512_blocks(inode) /
-	    (ext2_superblock_get_block_size(sb) / 512);
-}
-
-/**
- * Get inode flags
- * 
- * @param inode pointer to inode
- */
-uint32_t ext2_inode_get_flags(ext2_inode_t *inode) {
-	return uint32_t_le2host(inode->flags);
-}
-
-/**
- * Get direct block ID
- * 
- * @param inode pointer to inode
- * @param idx Index to block. Valid values are 0 <= idx < 12
- */
-uint32_t ext2_inode_get_direct_block(ext2_inode_t *inode, uint8_t idx)
-{
-	assert(idx < EXT2_INODE_DIRECT_BLOCKS);
-	return uint32_t_le2host(inode->direct_blocks[idx]);
-}
-
-/**
- * Get indirect block ID
- * 
- * @param inode pointer to inode
- * @param idx Indirection level. Valid values are 0 <= idx < 3, where 0 is
- *            singly-indirect block and 2 is triply-indirect-block
- */
-uint32_t ext2_inode_get_indirect_block(ext2_inode_t *inode, uint8_t idx)
-{
-	assert(idx < 3);
-	return uint32_t_le2host(inode->indirect_blocks[idx]);
-}
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_inode.h
===================================================================
--- uspace/lib/ext2/libext2_inode.h	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,103 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#ifndef LIBEXT2_LIBEXT2_INODE_H_
-#define LIBEXT2_LIBEXT2_INODE_H_
-
-#include <block.h>
-#include "libext2_superblock.h"
-
-typedef struct ext2_inode {
-	uint16_t mode;
-	uint16_t user_id;
-	uint32_t size;
-	uint8_t unused[16];
-	uint16_t group_id;
-	uint16_t usage_count; // Hard link count, when 0 the inode is to be freed
-	uint32_t reserved_512_blocks; // Size of this inode in 512-byte blocks
-	uint32_t flags;
-	uint8_t unused2[4];
-	uint32_t direct_blocks[12]; // Direct block ids stored in this inode
-	uint32_t indirect_blocks[3];
-	uint32_t version;
-	uint32_t file_acl;
-	union {
-		uint32_t dir_acl;
-		uint32_t size_high; // For regular files in version >= 1
-	} __attribute__ ((packed));
-	uint8_t unused3[6];
-	uint16_t mode_high; // Hurd only
-	uint16_t user_id_high; // Linux/Hurd only
-	uint16_t group_id_high; // Linux/Hurd only
-} __attribute__ ((packed)) ext2_inode_t;
-
-#define EXT2_INODE_MODE_FIFO		0x1000
-#define EXT2_INODE_MODE_CHARDEV		0x2000
-#define EXT2_INODE_MODE_DIRECTORY	0x4000
-#define EXT2_INODE_MODE_BLOCKDEV	0x6000
-#define EXT2_INODE_MODE_FILE		0x8000
-#define EXT2_INODE_MODE_SOFTLINK	0xA000
-#define EXT2_INODE_MODE_SOCKET		0xC000
-#define EXT2_INODE_MODE_ACCESS_MASK	0x0FFF
-#define EXT2_INODE_MODE_TYPE_MASK	0xF000
-#define EXT2_INODE_DIRECT_BLOCKS	12
-
-#define EXT2_INODE_ROOT_INDEX		2
-
-typedef struct ext2_inode_ref {
-	block_t *block; // Reference to a block containing this inode
-	ext2_inode_t *inode;
-	uint32_t index; // Index number of this inode
-} ext2_inode_ref_t;
-
-extern uint32_t ext2_inode_get_mode(ext2_superblock_t *, ext2_inode_t *);
-extern bool ext2_inode_is_type(ext2_superblock_t *, ext2_inode_t *, uint32_t);
-extern uint32_t ext2_inode_get_user_id(ext2_superblock_t *, ext2_inode_t *);
-extern uint64_t ext2_inode_get_size(ext2_superblock_t *, ext2_inode_t *);
-extern uint32_t ext2_inode_get_group_id(ext2_superblock_t *, ext2_inode_t *);
-extern uint16_t ext2_inode_get_usage_count(ext2_inode_t *);
-extern uint32_t ext2_inode_get_reserved_512_blocks(ext2_inode_t *);
-extern uint32_t ext2_inode_get_reserved_blocks(ext2_superblock_t *, 
-    ext2_inode_t *);
-extern uint32_t ext2_inode_get_flags(ext2_inode_t *);
-extern uint32_t ext2_inode_get_direct_block(ext2_inode_t *, uint8_t);
-extern uint32_t ext2_inode_get_indirect_block(ext2_inode_t *, uint8_t level);
-
-
-
-#endif
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_superblock.c
===================================================================
--- uspace/lib/ext2/libext2_superblock.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,409 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#include "libext2.h"
-#include <errno.h>
-#include <malloc.h>
-#include <block.h>
-#include <byteorder.h>
-
-/**
- * Return a magic number from ext2 superblock, this should be equal to
- * EXT_SUPERBLOCK_MAGIC for valid ext2 superblock
- * 
- * @param sb pointer to superblock
- */
-uint16_t ext2_superblock_get_magic(ext2_superblock_t *sb)
-{
-	return uint16_t_le2host(sb->magic);
-}
-
-/**
- * Get the position of first ext2 data block (i.e. the block number
- * containing main superblock)
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_first_block(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->first_block);
-}
-
-/**
- * Get the number of bits to shift a value of 1024 to the left necessary
- * to get the size of a block
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_block_size_log2(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->block_size_log2);
-}
-
-/**
- * Get the size of a block, in bytes 
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_block_size(ext2_superblock_t *sb)
-{
-	return 1024 << ext2_superblock_get_block_size_log2(sb);
-}
-
-/**
- * Get the number of bits to shift a value of 1024 to the left necessary
- * to get the size of a fragment (note that this is a signed integer and
- * if negative, the value should be shifted to the right instead)
- * 
- * @param sb pointer to superblock
- */
-int32_t ext2_superblock_get_fragment_size_log2(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->fragment_size_log2);
-}
-
-/**
- * Get the size of a fragment, in bytes 
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_fragment_size(ext2_superblock_t *sb)
-{
-	int32_t log = ext2_superblock_get_fragment_size_log2(sb);
-	if (log >= 0) {
-		return 1024 << log;
-	}
-	else {
-		return 1024 >> -log;
-	}
-}
-
-/**
- * Get number of blocks per block group
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_blocks_per_group(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->blocks_per_group);
-}
-
-/**
- * Get number of fragments per block group
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_fragments_per_group(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->fragments_per_group);
-}
-
-/**
- * Get filesystem state
- * 
- * @param sb pointer to superblock
- */
-uint16_t ext2_superblock_get_state(ext2_superblock_t *sb)
-{
-	return uint16_t_le2host(sb->state);
-}
-
-/**
- * Get minor revision number
- * 
- * @param sb pointer to superblock
- */
-uint16_t ext2_superblock_get_rev_minor(ext2_superblock_t *sb)
-{
-	return uint16_t_le2host(sb->rev_minor);
-}
-
-/**
- * Get major revision number
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_rev_major(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->rev_major);
-}
-
-/**
- * Get index of first regular inode
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_first_inode(ext2_superblock_t *sb)
-{
-	if (ext2_superblock_get_rev_major(sb) == 0) {
-		return EXT2_REV0_FIRST_INODE;
-	}
-	return uint32_t_le2host(sb->first_inode);
-}
-
-/**
- * Get size of inode
- * 
- * @param sb pointer to superblock
- */
-uint16_t ext2_superblock_get_inode_size(ext2_superblock_t *sb)
-{
-	if (ext2_superblock_get_rev_major(sb) == 0) {
-		return EXT2_REV0_INODE_SIZE;
-	}
-	return uint16_t_le2host(sb->inode_size);
-}
-
-/**
- * Get total inode count
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_total_inode_count(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->total_inode_count);
-}
-
-/**
- * Get total block count
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_total_block_count(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->total_block_count);
-}
-
-/**
- * Get amount of blocks reserved for the superuser
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_reserved_block_count(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->reserved_block_count);
-}
-
-/**
- * Get amount of free blocks
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_free_block_count(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->free_block_count);
-}
-
-/**
- * Get amount of free inodes
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_free_inode_count(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->free_inode_count);
-}
-
-/**
- * Get id of operating system that created the filesystem
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_os(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->os);
-}
-
-/**
- * Get count of inodes per block group
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_inodes_per_group(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->inodes_per_group);
-}
-
-/**
- * Get compatible features flags
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_features_compatible(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->features_compatible);
-}
-
-/**
- * Get incompatible features flags
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_features_incompatible(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->features_incompatible);
-}
-
-/**
- * Get read-only compatible features flags
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_features_read_only(ext2_superblock_t *sb)
-{
-	return uint32_t_le2host(sb->features_read_only);
-}
-
-/**
- * Compute count of block groups present in the filesystem
- * 
- * Note: This function works only for correct filesystem,
- *       i.e. it assumes that total block count > 0 and
- *       blocks per group > 0
- * 
- * Example:
- *   If there are 3 blocks per group, the result should be as follows:
- *   Total blocks	Result
- *   1				1
- *   2				1
- *   3				1
- *   4				2
- * 
- * 
- * @param sb pointer to superblock
- */
-uint32_t ext2_superblock_get_block_group_count(ext2_superblock_t *sb)
-{
-	/* We add one to the result because e.g. 2/3 = 0, while to store
-	 *  2 blocks in 3-block group we need one (1) block group
-	 * 
-	 * We subtract one first because of special case that to store e.g.
-	 *  3 blocks in a 3-block group we need only one group
-	 *  (and 3/3 yields one - this is one more that we want as we
-	 *   already add one at the end)
-	 */ 
-	return ((ext2_superblock_get_total_block_count(sb)-1) / 
-	    ext2_superblock_get_blocks_per_group(sb))+1;
-}
-
-/** Read a superblock directly from device (i.e. no libblock cache)
- * 
- * @param service_id	Service ID of the block device.
- * @param superblock	Pointer where to store pointer to new superblock
- * 
- * @return		EOK on success or negative error code on failure.
- */
-int ext2_superblock_read_direct(service_id_t service_id,
-    ext2_superblock_t **superblock)
-{
-	void *data;
-	int rc;
-	
-	data = malloc(EXT2_SUPERBLOCK_SIZE);
-	if (data == NULL) {
-		return ENOMEM;
-	}
-	
-	rc = block_read_bytes_direct(service_id, EXT2_SUPERBLOCK_OFFSET,
-	    EXT2_SUPERBLOCK_SIZE, data);
-	if (rc != EOK) {
-		free(data);
-		return rc;
-	}
-	
-	(*superblock) = data;
-	return EOK;
-}
-
-/** Check a superblock for sanity
- * 
- * @param sb	Pointer to superblock
- * 
- * @return		EOK on success or negative error code on failure.
- */
-int ext2_superblock_check_sanity(ext2_superblock_t *sb)
-{
-	if (ext2_superblock_get_magic(sb) != EXT2_SUPERBLOCK_MAGIC) {
-		return ENOTSUP;
-	}
-	
-	if (ext2_superblock_get_rev_major(sb) > 1) {
-		return ENOTSUP;
-	}
-	
-	if (ext2_superblock_get_total_inode_count(sb) == 0) {
-		return ENOTSUP;
-	}
-	
-	if (ext2_superblock_get_total_block_count(sb) == 0) {
-		return ENOTSUP;
-	}
-	
-	if (ext2_superblock_get_blocks_per_group(sb) == 0) {
-		return ENOTSUP;
-	}
-	
-	if (ext2_superblock_get_fragments_per_group(sb) == 0) {
-		return ENOTSUP;
-	}
-	
-	/* We don't support fragments smaller than block */
-	if (ext2_superblock_get_block_size(sb) != 
-		    ext2_superblock_get_fragment_size(sb)) {
-		return ENOTSUP;
-	}
-	if (ext2_superblock_get_blocks_per_group(sb) !=
-		    ext2_superblock_get_fragments_per_group(sb)) {
-		return ENOTSUP;
-	}
-	
-	if (ext2_superblock_get_inodes_per_group(sb) == 0) {
-		return ENOTSUP;
-	}
-	
-	if (ext2_superblock_get_inode_size(sb) < 128) {
-		return ENOTSUP;
-	}
-	
-	if (ext2_superblock_get_first_inode(sb) < 11) {
-		return ENOTSUP;
-	}
-	
-	return EOK;
-}
-
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_superblock.h
===================================================================
--- uspace/lib/ext2/libext2_superblock.h	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,118 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 libext2
- * @{
- */
-/**
- * @file
- */
-
-#ifndef LIBEXT2_LIBEXT2_SUPERBLOCK_H_
-#define LIBEXT2_LIBEXT2_SUPERBLOCK_H_
-
-#include <block.h>
-
-typedef struct ext2_superblock {
-	uint32_t	total_inode_count; // Total number of inodes
-	uint32_t	total_block_count; // Total number of blocks
-	uint32_t	reserved_block_count; // Total number of reserved blocks
-	uint32_t	free_block_count; // Total number of free blocks
-	uint32_t	free_inode_count; // Total number of free inodes
-	uint32_t	first_block; // Block containing the superblock (either 0 or 1)
-	uint32_t	block_size_log2; // log_2(block_size)
-	int32_t		fragment_size_log2; // log_2(fragment size)
-	uint32_t	blocks_per_group; // Number of blocks in one block group
-	uint32_t	fragments_per_group; // Number of fragments per block group
-	uint32_t	inodes_per_group; // Number of inodes per block group
-	uint8_t		unused2[12];
-	uint16_t	magic; // Magic value
-	uint16_t	state; // State (mounted/unmounted)
-	uint16_t	error_behavior; // What to do when errors are encountered
-	uint16_t	rev_minor; // Minor revision level
-	uint8_t		unused3[8];
-	uint32_t	os; // OS that created the filesystem
-	uint32_t	rev_major; // Major revision level
-	uint8_t		unused4[4];
-	
-	// Following is for ext2 revision 1 only
-	uint32_t	first_inode;
-	uint16_t	inode_size;
-	uint16_t	unused5;
-	uint32_t	features_compatible;
-	uint32_t	features_incompatible;
-	uint32_t	features_read_only;
-	uint8_t		uuid[16]; // UUID TODO: Create a library for UUIDs
-	uint8_t		volume_name[16];
-
-// TODO: add __attribute__((aligned(...)) for better performance?
-//       (it is necessary to ensure the superblock is correctly aligned then
-//        though)
-} __attribute__ ((packed)) ext2_superblock_t;
-
-#define EXT2_SUPERBLOCK_MAGIC		0xEF53
-#define EXT2_SUPERBLOCK_SIZE		1024
-#define EXT2_SUPERBLOCK_OFFSET		1024
-#define EXT2_SUPERBLOCK_LAST_BYTE	(EXT2_SUPERBLOCK_OFFSET + \
-									 EXT2_SUPERBLOCK_SIZE -1)
-#define EXT2_SUPERBLOCK_OS_LINUX	0
-#define EXT2_SUPERBLOCK_OS_HURD		1
-
-
-extern uint16_t	ext2_superblock_get_magic(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_first_block(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_block_size_log2(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_block_size(ext2_superblock_t *);
-extern int32_t	ext2_superblock_get_fragment_size_log2(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_fragment_size(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_blocks_per_group(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_fragments_per_group(ext2_superblock_t *);
-extern uint16_t	ext2_superblock_get_state(ext2_superblock_t *);
-extern uint16_t	ext2_superblock_get_rev_minor(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_rev_major(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_os(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_first_inode(ext2_superblock_t *);
-extern uint16_t	ext2_superblock_get_inode_size(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_total_inode_count(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_total_block_count(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_reserved_block_count(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_free_block_count(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_free_inode_count(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_block_group_count(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_inodes_per_group(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_features_compatible(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_features_incompatible(ext2_superblock_t *);
-extern uint32_t	ext2_superblock_get_features_read_only(ext2_superblock_t *);
-
-extern int ext2_superblock_read_direct(service_id_t, ext2_superblock_t **);
-extern int ext2_superblock_check_sanity(ext2_superblock_t *);
-
-#endif
-
-/** @}
- */
Index: uspace/srv/fs/ext2fs/Makefile
===================================================================
--- uspace/srv/fs/ext2fs/Makefile	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,40 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# Copyright (c) 2010 Martin Sucha
-# 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 $(LIBEXT2_PREFIX)/libext2.a
-EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX) -I$(LIBEXT2_PREFIX)
-BINARY = ext2fs
-
-SOURCES = \
-	ext2fs.c \
-	ext2fs_ops.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/fs/ext2fs/ext2fs.c
===================================================================
--- uspace/srv/fs/ext2fs/ext2fs.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,99 +1,0 @@
-/*
- * Copyright (c) 2006 Martin Decky
- * Copyright (c) 2011 Martin Sucha
- * 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	ext2.c
- * @brief	EXT2 file system driver for HelenOS.
- */
-
-#include "ext2fs.h"
-#include <ipc/services.h>
-#include <ns.h>
-#include <async.h>
-#include <errno.h>
-#include <unistd.h>
-#include <task.h>
-#include <stdio.h>
-#include <libfs.h>
-#include "../../vfs/vfs.h"
-
-#define NAME	"ext2fs"
-
-vfs_info_t ext2fs_vfs_info = {
-	.name = NAME,
-	.instance = 0,
-};
-
-int main(int argc, char **argv)
-{
-	printf(NAME ": HelenOS EXT2 file system server\n");
-
-	if (argc == 3) {
-		if (!str_cmp(argv[1], "--instance"))
-			ext2fs_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 = ext2fs_global_init();
-	if (rc != EOK) {
-		printf(NAME ": Failed global initialization\n");
-		return 1;
-	}	
-		
-	rc = fs_register(vfs_sess, &ext2fs_vfs_info, &ext2fs_ops,
-	    &ext2fs_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/ext2fs/ext2fs.h
===================================================================
--- uspace/srv/fs/ext2fs/ext2fs.h	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,52 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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 EXT2FS_EXT2FS_H_
-#define EXT2FS_EXT2FS_H_
-
-#include <libext2.h>
-#include <libfs.h>
-#include <sys/types.h>
-
-#define min(a, b)		((a) < (b) ? (a) : (b))
-
-extern vfs_out_ops_t ext2fs_ops;
-extern libfs_ops_t ext2fs_libfs_ops;
-
-extern int ext2fs_global_init(void);
-extern int ext2fs_global_fini(void);
-
-#endif
-
-/**
- * @}
- */
Index: uspace/srv/fs/ext2fs/ext2fs_ops.c
===================================================================
--- uspace/srv/fs/ext2fs/ext2fs_ops.c	(revision d1538a1fa3100ff880b0dd2c1b9e79fdec6ea762)
+++ 	(revision )
@@ -1,976 +1,0 @@
-/*
- * Copyright (c) 2011 Martin Sucha
- * 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	ext2fs_ops.c
- * @brief	Implementation of VFS operations for the EXT2 file system server.
- */
-
-#include "ext2fs.h"
-#include "../../vfs/vfs.h"
-#include <libfs.h>
-#include <block.h>
-#include <libext2.h>
-#include <ipc/services.h>
-#include <ipc/loc.h>
-#include <macros.h>
-#include <async.h>
-#include <errno.h>
-#include <str.h>
-#include <byteorder.h>
-#include <adt/hash_table.h>
-#include <adt/hash.h>
-#include <adt/list.h>
-#include <assert.h>
-#include <fibril_synch.h>
-#include <sys/mman.h>
-#include <align.h>
-#include <adt/hash_table.h>
-#include <sys/typefmt.h>
-#include <malloc.h>
-#include <stdio.h>
-#include <inttypes.h>
-
-#define EXT2FS_NODE(node)	((node) ? (ext2fs_node_t *) (node)->data : NULL)
-#define EXT2FS_DBG(format, ...) {if (false) printf("ext2fs: %s: " format "\n", __FUNCTION__, ##__VA_ARGS__);}
-
-typedef struct ext2fs_instance {
-	link_t link;
-	service_id_t service_id;
-	ext2_filesystem_t *filesystem;
-	unsigned int open_nodes_count;
-} ext2fs_instance_t;
-
-typedef struct ext2fs_node {
-	ext2fs_instance_t *instance;
-	ext2_inode_ref_t *inode_ref;
-	fs_node_t *fs_node;
-	ht_link_t link;
-	unsigned int references;
-} ext2fs_node_t;
-
-/*
- * Forward declarations of auxiliary functions
- */
-static int ext2fs_instance_get(service_id_t, ext2fs_instance_t **);
-static int ext2fs_read_directory(ipc_callid_t, aoff64_t, size_t,
-    ext2fs_instance_t *, ext2_inode_ref_t *, size_t *);
-static int ext2fs_read_file(ipc_callid_t, aoff64_t, size_t, ext2fs_instance_t *,
-    ext2_inode_ref_t *, size_t *);
-static bool ext2fs_is_dots(const uint8_t *, size_t);
-static int ext2fs_node_get_core(fs_node_t **, ext2fs_instance_t *, fs_index_t);
-static int ext2fs_node_put_core(ext2fs_node_t *);
-
-/*
- * Forward declarations of EXT2 libfs operations.
- */
-static int ext2fs_root_get(fs_node_t **, service_id_t);
-static int ext2fs_match(fs_node_t **, fs_node_t *, const char *);
-static int ext2fs_node_get(fs_node_t **, service_id_t, fs_index_t);
-static int ext2fs_node_open(fs_node_t *);
-static int ext2fs_node_put(fs_node_t *);
-static int ext2fs_create_node(fs_node_t **, service_id_t, int);
-static int ext2fs_destroy_node(fs_node_t *);
-static int ext2fs_link(fs_node_t *, fs_node_t *, const char *);
-static int ext2fs_unlink(fs_node_t *, fs_node_t *, const char *);
-static int ext2fs_has_children(bool *, fs_node_t *);
-static fs_index_t ext2fs_index_get(fs_node_t *);
-static aoff64_t ext2fs_size_get(fs_node_t *);
-static unsigned ext2fs_lnkcnt_get(fs_node_t *);
-static bool ext2fs_is_directory(fs_node_t *);
-static bool ext2fs_is_file(fs_node_t *node);
-static service_id_t ext2fs_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 
- */
-
-typedef struct {
-	service_id_t service_id;
-	fs_index_t index;
-} node_key_t;
-
-static size_t open_nodes_key_hash(void *key)
-{
-	node_key_t *node_key = (node_key_t*)key;
-	return hash_combine(node_key->service_id, node_key->index);
-}
-
-static size_t open_nodes_hash(const ht_link_t *item)
-{
-	ext2fs_node_t *enode = hash_table_get_inst(item, ext2fs_node_t, link);
-
-	assert(enode->instance);
-	assert(enode->inode_ref);
-	
-	return hash_combine(enode->instance->service_id, enode->inode_ref->index);
-}
-
-static bool open_nodes_key_equal(void *key, const ht_link_t *item)
-{
-	node_key_t *node_key = (node_key_t*)key;
-	ext2fs_node_t *enode = hash_table_get_inst(item, ext2fs_node_t, link);
-	
-	return node_key->service_id == enode->instance->service_id
-		&& node_key->index == enode->inode_ref->index;
-}
-
-static hash_table_ops_t open_nodes_ops = {
-	.hash = open_nodes_hash,
-	.key_hash = open_nodes_key_hash,
-	.key_equal = open_nodes_key_equal,
-	.equal = NULL,
-	.remove_callback = NULL,
-};
-
-/**
- * 
- */
-int ext2fs_global_init(void)
-{
-	if (!hash_table_create(&open_nodes, 0, 0, &open_nodes_ops)) {
-		return ENOMEM;
-	}
-	return EOK;
-}
-
-int ext2fs_global_fini(void)
-{
-	hash_table_destroy(&open_nodes);
-	return EOK;
-}
-
-
-/*
- * EXT2 libfs operations.
- */
-
-/**
- * Find an instance of filesystem for the given service_id
- */
-int ext2fs_instance_get(service_id_t service_id, ext2fs_instance_t **inst)
-{
-	EXT2FS_DBG("(%" PRIun ", -)", service_id);
-	ext2fs_instance_t *tmp;
-	
-	fibril_mutex_lock(&instance_list_mutex);
-
-	if (list_empty(&instance_list)) {
-		EXT2FS_DBG("list empty");
-		fibril_mutex_unlock(&instance_list_mutex);
-		return EINVAL;
-	}
-
-	list_foreach(instance_list, link) {
-		tmp = list_get_instance(link, ext2fs_instance_t, link);
-		
-		if (tmp->service_id == service_id) {
-			*inst = tmp;
-			fibril_mutex_unlock(&instance_list_mutex);
-			return EOK;
-		}
-	}
-	
-	EXT2FS_DBG("not found");
-	
-	fibril_mutex_unlock(&instance_list_mutex);
-	return EINVAL;
-}
-
-
-
-int ext2fs_root_get(fs_node_t **rfn, service_id_t service_id)
-{
-	EXT2FS_DBG("(-, %" PRIun ")", service_id);
-	return ext2fs_node_get(rfn, service_id, EXT2_INODE_ROOT_INDEX);
-}
-
-int ext2fs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
-{
-	EXT2FS_DBG("(-,-,%s)", component);
-	ext2fs_node_t *eparent = EXT2FS_NODE(pfn);
-	ext2_filesystem_t *fs;
-	ext2_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 (!ext2_inode_is_type(fs->superblock, eparent->inode_ref->inode,
-	    EXT2_INODE_MODE_DIRECTORY)) {
-		return ENOTDIR;
-	}
-	
-	rc = ext2_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 = ext2_directory_entry_ll_get_inode(it.current);
-		
-		/* ignore empty directory entries */
-		if (inode != 0) {
-			name_size = ext2_directory_entry_ll_get_name_length(fs->superblock,
-				it.current);
-
-			if (name_size == component_size && bcmp(component, &it.current->name,
-				    name_size) == 0) {
-				rc = ext2fs_node_get_core(rfn, eparent->instance,
-					inode);
-				if (rc != EOK) {
-					ext2_directory_iterator_fini(&it);
-					return rc;
-				}
-				found = true;
-				break;
-			}
-		}
-		
-		rc = ext2_directory_iterator_next(&it);
-		if (rc != EOK) {
-			ext2_directory_iterator_fini(&it);
-			return rc;
-		}
-	}
-	
-	ext2_directory_iterator_fini(&it);
-	
-	if (!found) {
-		return ENOENT;
-	}
-	
-	return EOK;
-}
-
-/** Instantiate a EXT2 in-core node. */
-int ext2fs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index)
-{
-	EXT2FS_DBG("(-,%" PRIun ",%u)", service_id, index);
-	
-	ext2fs_instance_t *inst = NULL;
-	int rc;
-	
-	rc = ext2fs_instance_get(service_id, &inst);
-	if (rc != EOK) {
-		return rc;
-	}
-	
-	return ext2fs_node_get_core(rfn, inst, index);
-}
-
-int ext2fs_node_get_core(fs_node_t **rfn, ext2fs_instance_t *inst,
-		fs_index_t index)
-{
-	int rc;
-	fs_node_t *node = NULL;
-	ext2fs_node_t *enode = NULL;
-	
-	ext2_inode_ref_t *inode_ref = NULL;
-
-	fibril_mutex_lock(&open_nodes_lock);
-	
-	/* Check if the node is not already open */
-	node_key_t key = {
-		.service_id = inst->service_id,
-		.index = index
-	};
-	ht_link_t *already_open = hash_table_find(&open_nodes, &key);
-
-	if (already_open) {
-		enode = hash_table_get_inst(already_open, ext2fs_node_t, link);
-		*rfn = enode->fs_node;
-		enode->references++;
-
-		fibril_mutex_unlock(&open_nodes_lock);
-		return EOK;
-	}
-
-	enode = malloc(sizeof(ext2fs_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 = ext2_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;
-	
-	node->data = enode;
-	*rfn = node;
-	
-	hash_table_insert(&open_nodes, &enode->link);
-	inst->open_nodes_count++;
-	
-	EXT2FS_DBG("inode: %u", inode_ref->index);
-	
-	EXT2FS_DBG("EOK");
-
-	fibril_mutex_unlock(&open_nodes_lock);
-	return EOK;
-}
-
-int ext2fs_node_open(fs_node_t *fn)
-{
-	EXT2FS_DBG("");
-	/*
-	 * Opening a file is stateless, nothing
-	 * to be done here.
-	 */
-	return EOK;
-}
-
-int ext2fs_node_put(fs_node_t *fn)
-{
-	EXT2FS_DBG("");
-	int rc;
-	ext2fs_node_t *enode = EXT2FS_NODE(fn);
-	
-	fibril_mutex_lock(&open_nodes_lock);
-
-	assert(enode->references > 0);
-	enode->references--;
-	if (enode->references == 0) {
-		rc = ext2fs_node_put_core(enode);
-		if (rc != EOK) {
-			fibril_mutex_unlock(&open_nodes_lock);
-			return rc;
-		}
-	}
-
-	fibril_mutex_unlock(&open_nodes_lock);
-	
-	return EOK;
-}
-
-int ext2fs_node_put_core(ext2fs_node_t *enode)
-{
-	node_key_t key = {
-		.service_id = enode->instance->service_id,
-		.index = enode->inode_ref->index
-	};
-
-	hash_table_remove(&open_nodes, &key);
-	
-	assert(enode->instance->open_nodes_count > 0);
-	enode->instance->open_nodes_count--;
-
-	int rc = ext2_filesystem_put_inode_ref(enode->inode_ref);
-	if (rc != EOK) {
-		EXT2FS_DBG("ext2_filesystem_put_inode_ref failed");
-		return rc;
-	}
-
-	free(enode->fs_node);
-	free(enode);
-	return EOK;
-}
-
-int ext2fs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
-{
-	EXT2FS_DBG("");
-	// TODO
-	return ENOTSUP;
-}
-
-int ext2fs_destroy_node(fs_node_t *fn)
-{
-	EXT2FS_DBG("");
-	// TODO
-	return ENOTSUP;
-}
-
-int ext2fs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
-{
-	EXT2FS_DBG("");
-	// TODO
-	return ENOTSUP;
-}
-
-int ext2fs_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *nm)
-{
-	EXT2FS_DBG("");
-	// TODO
-	return ENOTSUP;
-}
-
-int ext2fs_has_children(bool *has_children, fs_node_t *fn)
-{
-	EXT2FS_DBG("");
-	ext2fs_node_t *enode = EXT2FS_NODE(fn);
-	ext2_directory_iterator_t it;
-	ext2_filesystem_t *fs;
-	int rc;
-	bool found = false;
-	size_t name_size;
-
-	fs = enode->instance->filesystem;
-
-	if (!ext2_inode_is_type(fs->superblock, enode->inode_ref->inode,
-	    EXT2_INODE_MODE_DIRECTORY)) {
-		*has_children = false;
-		EXT2FS_DBG("EOK - false");
-		return EOK;
-	}
-	
-	rc = ext2_directory_iterator_init(&it, fs, enode->inode_ref, 0);
-	if (rc != EOK) {
-		EXT2FS_DBG("error %u", rc);
-		return rc;
-	}
-	
-	/* Find a non-empty directory entry */
-	while (it.current != NULL) {
-		if (it.current->inode != 0) {
-			name_size = ext2_directory_entry_ll_get_name_length(fs->superblock,
-				it.current);
-			if (!ext2fs_is_dots(&it.current->name, name_size)) {
-				found = true;
-				break;
-			}
-		}
-		
-		rc = ext2_directory_iterator_next(&it);
-		if (rc != EOK) {
-			ext2_directory_iterator_fini(&it);
-			EXT2FS_DBG("error %u", rc);
-			return rc;
-		}
-	}
-	
-	rc = ext2_directory_iterator_fini(&it);
-	if (rc != EOK) {
-		EXT2FS_DBG("error %u", rc);
-		return rc;
-	}
-
-	*has_children = found;
-	EXT2FS_DBG("EOK");
-	
-	return EOK;
-}
-
-
-fs_index_t ext2fs_index_get(fs_node_t *fn)
-{
-	ext2fs_node_t *enode = EXT2FS_NODE(fn);
-	EXT2FS_DBG("%u", enode->inode_ref->index);
-	return enode->inode_ref->index;
-}
-
-aoff64_t ext2fs_size_get(fs_node_t *fn)
-{
-	ext2fs_node_t *enode = EXT2FS_NODE(fn);
-	aoff64_t size = ext2_inode_get_size(enode->instance->filesystem->superblock,
-	    enode->inode_ref->inode);
-	EXT2FS_DBG("%" PRIu64, size);
-	return size;
-}
-
-unsigned ext2fs_lnkcnt_get(fs_node_t *fn)
-{
-	ext2fs_node_t *enode = EXT2FS_NODE(fn);
-	unsigned count = ext2_inode_get_usage_count(enode->inode_ref->inode);
-	EXT2FS_DBG("%u", count);
-	return count;
-}
-
-bool ext2fs_is_directory(fs_node_t *fn)
-{
-	ext2fs_node_t *enode = EXT2FS_NODE(fn);
-	bool is_dir = ext2_inode_is_type(enode->instance->filesystem->superblock,
-	    enode->inode_ref->inode, EXT2_INODE_MODE_DIRECTORY);
-	EXT2FS_DBG("%s", is_dir ? "true" : "false");
-	EXT2FS_DBG("%u", enode->inode_ref->index);
-	return is_dir;
-}
-
-bool ext2fs_is_file(fs_node_t *fn)
-{
-	ext2fs_node_t *enode = EXT2FS_NODE(fn);
-	bool is_file = ext2_inode_is_type(enode->instance->filesystem->superblock,
-	    enode->inode_ref->inode, EXT2_INODE_MODE_FILE);
-	EXT2FS_DBG("%s", is_file ? "true" : "false");
-	return is_file;
-}
-
-service_id_t ext2fs_service_get(fs_node_t *fn)
-{
-	EXT2FS_DBG("");
-	ext2fs_node_t *enode = EXT2FS_NODE(fn);
-	return enode->instance->service_id;
-}
-
-/** libfs operations */
-libfs_ops_t ext2fs_libfs_ops = {
-	.root_get = ext2fs_root_get,
-	.match = ext2fs_match,
-	.node_get = ext2fs_node_get,
-	.node_open = ext2fs_node_open,
-	.node_put = ext2fs_node_put,
-	.create = ext2fs_create_node,
-	.destroy = ext2fs_destroy_node,
-	.link = ext2fs_link,
-	.unlink = ext2fs_unlink,
-	.has_children = ext2fs_has_children,
-	.index_get = ext2fs_index_get,
-	.size_get = ext2fs_size_get,
-	.lnkcnt_get = ext2fs_lnkcnt_get,
-	.is_directory = ext2fs_is_directory,
-	.is_file = ext2fs_is_file,
-	.service_get = ext2fs_service_get
-};
-
-/*
- * VFS operations.
- */
-
-static int ext2fs_mounted(service_id_t service_id, const char *opts,
-   fs_index_t *index, aoff64_t *size, unsigned *lnkcnt)
-{
-	EXT2FS_DBG("");
-	int rc;
-	ext2_filesystem_t *fs;
-	ext2fs_instance_t *inst;
-	bool read_only;
-	
-	/* Allocate libext2 filesystem structure */
-	fs = (ext2_filesystem_t *) malloc(sizeof(ext2_filesystem_t));
-	if (fs == NULL)
-		return ENOMEM;
-	
-	/* Allocate instance structure */
-	inst = (ext2fs_instance_t *) malloc(sizeof(ext2fs_instance_t));
-	if (inst == NULL) {
-		free(fs);
-		return ENOMEM;
-	}
-	
-	/* Initialize the filesystem  */
-	rc = ext2_filesystem_init(fs, service_id);
-	if (rc != EOK) {
-		free(fs);
-		free(inst);
-		return rc;
-	}
-	
-	/* Do some sanity checking */
-	rc = ext2_filesystem_check_sanity(fs);
-	if (rc != EOK) {
-		ext2_filesystem_fini(fs);
-		free(fs);
-		free(inst);
-		return rc;
-	}
-	
-	/* Check flags */
-	rc = ext2_filesystem_check_flags(fs, &read_only);
-	if (rc != EOK) {
-		ext2_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 = ext2fs_node_get_core(&root_node, inst, EXT2_INODE_ROOT_INDEX);
-	if (rc != EOK) {
-		ext2_filesystem_fini(fs);
-		free(fs);
-		free(inst);
-		return rc;
-	}
-	ext2fs_node_t *enode = EXT2FS_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 = EXT2_INODE_ROOT_INDEX;
-	*size = 0;
-	*lnkcnt = ext2_inode_get_usage_count(enode->inode_ref->inode);
-	
-	ext2fs_node_put(root_node);
-
-	return EOK;
-}
-
-static int ext2fs_unmounted(service_id_t service_id)
-{
-	EXT2FS_DBG("");
-	ext2fs_instance_t *inst;
-	int rc;
-	
-	rc = ext2fs_instance_get(service_id, &inst);
-	
-	if (rc != EOK)
-		return rc;
-	
-	fibril_mutex_lock(&open_nodes_lock);
-
-	EXT2FS_DBG("open_nodes_count = %d", inst->open_nodes_count)
-	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);
-	
-	ext2_filesystem_fini(inst->filesystem);
-	
-	return EOK;
-}
-
-static int
-ext2fs_read(service_id_t service_id, fs_index_t index, aoff64_t pos,
-    size_t *rbytes)
-{
-	EXT2FS_DBG("");
-	
-	ext2fs_instance_t *inst;
-	ext2_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 = ext2fs_instance_get(service_id, &inst);
-	if (rc != EOK) {
-		async_answer_0(callid, rc);
-		return rc;
-	}
-	
-	rc = ext2_filesystem_get_inode_ref(inst->filesystem, index, &inode_ref);
-	if (rc != EOK) {
-		async_answer_0(callid, rc);
-		return rc;
-	}
-	
-	if (ext2_inode_is_type(inst->filesystem->superblock, inode_ref->inode,
-	    EXT2_INODE_MODE_FILE)) {
-		rc = ext2fs_read_file(callid, pos, size, inst, inode_ref,
-		    rbytes);
-	} else if (ext2_inode_is_type(inst->filesystem->superblock,
-	    inode_ref->inode, EXT2_INODE_MODE_DIRECTORY)) {
-		rc = ext2fs_read_directory(callid, pos, size, inst, inode_ref,
-		    rbytes);
-	} else {
-		/* Other inode types not supported */
-		async_answer_0(callid, ENOTSUP);
-		rc = ENOTSUP;
-	}
-	
-	ext2_filesystem_put_inode_ref(inode_ref);
-	
-	return rc;
-}
-
-/**
- * Determine whether given directory entry name is . or ..
- */
-bool ext2fs_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 ext2fs_read_directory(ipc_callid_t callid, aoff64_t pos, size_t size,
-    ext2fs_instance_t *inst, ext2_inode_ref_t *inode_ref, size_t *rbytes)
-{
-	ext2_directory_iterator_t it;
-	aoff64_t next;
-	uint8_t *buf;
-	size_t name_size;
-	int rc;
-	bool found = false;
-	
-	rc = ext2_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 = ext2_directory_entry_ll_get_name_length(
-		    inst->filesystem->superblock, it.current);
-		
-		/* skip . and .. */
-		if (ext2fs_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) {
-			ext2_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 = ext2_directory_iterator_next(&it);
-		if (rc != EOK) {
-			ext2_directory_iterator_fini(&it);
-			async_answer_0(callid, rc);
-			return rc;
-		}
-	}
-	
-	if (found) {
-		rc = ext2_directory_iterator_next(&it);
-		if (rc != EOK)
-			return rc;
-		next = it.current_offset;
-	}
-	
-	rc = ext2_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 ext2fs_read_file(ipc_callid_t callid, aoff64_t pos, size_t size,
-    ext2fs_instance_t *inst, ext2_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 = ext2_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 = ext2_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 = ext2_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
-ext2fs_write(service_id_t service_id, fs_index_t index, aoff64_t pos,
-    size_t *wbytes, aoff64_t *nsize)
-{
-	EXT2FS_DBG("");
-	return ENOTSUP;
-}
-
-static int
-ext2fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t size)
-{
-	EXT2FS_DBG("");
-	return ENOTSUP;
-}
-
-static int ext2fs_close(service_id_t service_id, fs_index_t index)
-{
-	EXT2FS_DBG("");
-	return EOK;
-}
-
-static int ext2fs_destroy(service_id_t service_id, fs_index_t index)
-{
-	EXT2FS_DBG("");
-	return ENOTSUP;
-}
-
-static int ext2fs_sync(service_id_t service_id, fs_index_t index)
-{
-	EXT2FS_DBG("");
-	return ENOTSUP;
-}
-
-vfs_out_ops_t ext2fs_ops = {
-	.mounted = ext2fs_mounted,
-	.unmounted = ext2fs_unmounted,
-	.read = ext2fs_read,
-	.write = ext2fs_write,
-	.truncate = ext2fs_truncate,
-	.close = ext2fs_close,
-	.destroy = ext2fs_destroy,
-	.sync = ext2fs_sync,
-};
-
-/**
- * @}
- */
-
