Index: contrib/arch/uspace/srv/fs/fat/fat.bp
===================================================================
--- contrib/arch/uspace/srv/fs/fat/fat.bp	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ contrib/arch/uspace/srv/fs/fat/fat.bp	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -7,5 +7,5 @@
 			?ipc_m_data_write /* mount options */ ;
 			tentative {
-				[/uspace/lib/libblock/fnc.block_init%rd]
+				[/uspace/lib/block/fnc.block_init%rd]
 			}
 		} +
Index: uspace/app/bdsh/cmds/modules/bdd/bdd.c
===================================================================
--- uspace/app/bdsh/cmds/modules/bdd/bdd.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/app/bdsh/cmds/modules/bdd/bdd.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -38,5 +38,5 @@
 #include "cmds.h"
 
-#include <libblock.h>
+#include <block.h>
 #include <loc.h>
 #include <errno.h>
Index: uspace/app/blkdump/blkdump.c
===================================================================
--- uspace/app/blkdump/blkdump.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/app/blkdump/blkdump.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -40,5 +40,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <libblock.h>
+#include <block.h>
 #include <mem.h>
 #include <loc.h>
Index: uspace/app/ext2info/ext2info.c
===================================================================
--- uspace/app/ext2info/ext2info.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/app/ext2info/ext2info.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -40,5 +40,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <libblock.h>
+#include <block.h>
 #include <mem.h>
 #include <loc.h>
Index: uspace/app/mkexfat/mkexfat.c
===================================================================
--- uspace/app/mkexfat/mkexfat.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/app/mkexfat/mkexfat.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -38,5 +38,5 @@
 
 #include <stdio.h>
-#include <libblock.h>
+#include <block.h>
 #include <assert.h>
 #include <errno.h>
Index: uspace/app/mkfat/mkfat.c
===================================================================
--- uspace/app/mkfat/mkfat.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/app/mkfat/mkfat.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -40,5 +40,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <libblock.h>
+#include <block.h>
 #include <mem.h>
 #include <loc.h>
Index: uspace/app/mkmfs/mkmfs.c
===================================================================
--- uspace/app/mkmfs/mkmfs.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/app/mkmfs/mkmfs.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -39,5 +39,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <libblock.h>
+#include <block.h>
 #include <unistd.h>
 #include <errno.h>
Index: uspace/drv/bus/usb/usbmast/main.c
===================================================================
--- uspace/drv/bus/usb/usbmast/main.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/drv/bus/usb/usbmast/main.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -100,5 +100,5 @@
 static usbmast_fun_t *bd_srv_usbmast(bd_srv_t *bd)
 {
-	return (usbmast_fun_t *)bd->srvs->sarg;
+	return (usbmast_fun_t *) bd->srvs->sarg;
 }
 
Index: uspace/lib/block/Makefile
===================================================================
--- uspace/lib/block/Makefile	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/block/Makefile	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -32,5 +32,5 @@
 
 SOURCES = \
-	libblock.c
+	block.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/block/block.c
===================================================================
--- uspace/lib/block/block.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
+++ uspace/lib/block/block.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -0,0 +1,936 @@
+/*
+ * Copyright (c) 2008 Jakub Jermar
+ * Copyright (c) 2008 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 libblock
+ * @{
+ */
+/**
+ * @file
+ * @brief
+ */
+
+#include "../../srv/vfs/vfs.h"
+#include <ipc/loc.h>
+#include <ipc/services.h>
+#include <errno.h>
+#include <sys/mman.h>
+#include <async.h>
+#include <as.h>
+#include <assert.h>
+#include <bd.h>
+#include <fibril_synch.h>
+#include <adt/list.h>
+#include <adt/hash_table.h>
+#include <macros.h>
+#include <mem.h>
+#include <malloc.h>
+#include <stdio.h>
+#include <sys/typefmt.h>
+#include <stacktrace.h>
+#include "block.h"
+
+/** Lock protecting the device connection list */
+static FIBRIL_MUTEX_INITIALIZE(dcl_lock);
+/** Device connection list head. */
+static LIST_INITIALIZE(dcl);
+
+#define CACHE_BUCKETS_LOG2  10
+#define CACHE_BUCKETS       (1 << CACHE_BUCKETS_LOG2)
+
+typedef struct {
+	fibril_mutex_t lock;
+	size_t lblock_size;       /**< Logical block size. */
+	unsigned blocks_cluster;  /**< Physical blocks per block_t */
+	unsigned block_count;     /**< Total number of blocks. */
+	unsigned blocks_cached;   /**< Number of cached blocks. */
+	hash_table_t block_hash;
+	list_t free_list;
+	enum cache_mode mode;
+} cache_t;
+
+typedef struct {
+	link_t link;
+	service_id_t service_id;
+	async_sess_t *sess;
+	bd_t *bd;
+	void *bb_buf;
+	aoff64_t bb_addr;
+	size_t pblock_size;  /**< Physical block size. */
+	cache_t *cache;
+} devcon_t;
+
+static int read_blocks(devcon_t *, aoff64_t, size_t, void *, size_t);
+static int write_blocks(devcon_t *, aoff64_t, size_t, void *, size_t);
+static aoff64_t ba_ltop(devcon_t *, aoff64_t);
+
+static devcon_t *devcon_search(service_id_t service_id)
+{
+	fibril_mutex_lock(&dcl_lock);
+	
+	list_foreach(dcl, cur) {
+		devcon_t *devcon = list_get_instance(cur, devcon_t, link);
+		if (devcon->service_id == service_id) {
+			fibril_mutex_unlock(&dcl_lock);
+			return devcon;
+		}
+	}
+	
+	fibril_mutex_unlock(&dcl_lock);
+	return NULL;
+}
+
+static int devcon_add(service_id_t service_id, async_sess_t *sess,
+    size_t bsize, bd_t *bd)
+{
+	devcon_t *devcon;
+	
+	devcon = malloc(sizeof(devcon_t));
+	if (!devcon)
+		return ENOMEM;
+	
+	link_initialize(&devcon->link);
+	devcon->service_id = service_id;
+	devcon->sess = sess;
+	devcon->bd = bd;
+	devcon->bb_buf = NULL;
+	devcon->bb_addr = 0;
+	devcon->pblock_size = bsize;
+	devcon->cache = NULL;
+	
+	fibril_mutex_lock(&dcl_lock);
+	list_foreach(dcl, cur) {
+		devcon_t *d = list_get_instance(cur, devcon_t, link);
+		if (d->service_id == service_id) {
+			fibril_mutex_unlock(&dcl_lock);
+			free(devcon);
+			return EEXIST;
+		}
+	}
+	list_append(&devcon->link, &dcl);
+	fibril_mutex_unlock(&dcl_lock);
+	return EOK;
+}
+
+static void devcon_remove(devcon_t *devcon)
+{
+	fibril_mutex_lock(&dcl_lock);
+	list_remove(&devcon->link);
+	fibril_mutex_unlock(&dcl_lock);
+}
+
+int block_init(exch_mgmt_t mgmt, service_id_t service_id,
+    size_t comm_size)
+{
+	bd_t *bd;
+
+	async_sess_t *sess = loc_service_connect(mgmt, service_id,
+	    IPC_FLAG_BLOCKING);
+	if (!sess) {
+		return ENOENT;
+	}
+	
+	int rc = bd_open(sess, &bd);
+	if (rc != EOK) {
+		async_hangup(sess);
+		return rc;
+	}
+	
+	size_t bsize;
+	rc = bd_get_block_size(bd, &bsize);
+	if (rc != EOK) {
+		bd_close(bd);
+		async_hangup(sess);
+		return rc;
+	}
+	
+	rc = devcon_add(service_id, sess, bsize, bd);
+	if (rc != EOK) {
+		bd_close(bd);
+		async_hangup(sess);
+		return rc;
+	}
+	
+	return EOK;
+}
+
+void block_fini(service_id_t service_id)
+{
+	devcon_t *devcon = devcon_search(service_id);
+	assert(devcon);
+	
+	if (devcon->cache)
+		(void) block_cache_fini(service_id);
+	
+	devcon_remove(devcon);
+	
+	if (devcon->bb_buf)
+		free(devcon->bb_buf);
+	
+	bd_close(devcon->bd);
+	async_hangup(devcon->sess);
+	
+	free(devcon);
+}
+
+int block_bb_read(service_id_t service_id, aoff64_t ba)
+{
+	void *bb_buf;
+	int rc;
+
+	devcon_t *devcon = devcon_search(service_id);
+	if (!devcon)
+		return ENOENT;
+	if (devcon->bb_buf)
+		return EEXIST;
+	bb_buf = malloc(devcon->pblock_size);
+	if (!bb_buf)
+		return ENOMEM;
+
+	rc = read_blocks(devcon, 0, 1, bb_buf, devcon->pblock_size);
+	if (rc != EOK) {
+	    	free(bb_buf);
+		return rc;
+	}
+
+	devcon->bb_buf = bb_buf;
+	devcon->bb_addr = ba;
+
+	return EOK;
+}
+
+void *block_bb_get(service_id_t service_id)
+{
+	devcon_t *devcon = devcon_search(service_id);
+	assert(devcon);
+	return devcon->bb_buf;
+}
+
+static hash_index_t cache_hash(unsigned long *key)
+{
+	return MERGE_LOUP32(key[0], key[1]) & (CACHE_BUCKETS - 1);
+}
+
+static int cache_compare(unsigned long *key, hash_count_t keys, link_t *item)
+{
+	block_t *b = hash_table_get_instance(item, block_t, hash_link);
+	return b->lba == MERGE_LOUP32(key[0], key[1]);
+}
+
+static void cache_remove_callback(link_t *item)
+{
+}
+
+static hash_table_operations_t cache_ops = {
+	.hash = cache_hash,
+	.compare = cache_compare,
+	.remove_callback = cache_remove_callback
+};
+
+int block_cache_init(service_id_t service_id, size_t size, unsigned blocks,
+    enum cache_mode mode)
+{
+	devcon_t *devcon = devcon_search(service_id);
+	cache_t *cache;
+	if (!devcon)
+		return ENOENT;
+	if (devcon->cache)
+		return EEXIST;
+	cache = malloc(sizeof(cache_t));
+	if (!cache)
+		return ENOMEM;
+	
+	fibril_mutex_initialize(&cache->lock);
+	list_initialize(&cache->free_list);
+	cache->lblock_size = size;
+	cache->block_count = blocks;
+	cache->blocks_cached = 0;
+	cache->mode = mode;
+
+	/* Allow 1:1 or small-to-large block size translation */
+	if (cache->lblock_size % devcon->pblock_size != 0) {
+		free(cache);
+		return ENOTSUP;
+	}
+
+	cache->blocks_cluster = cache->lblock_size / devcon->pblock_size;
+
+	if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2,
+	    &cache_ops)) {
+		free(cache);
+		return ENOMEM;
+	}
+
+	devcon->cache = cache;
+	return EOK;
+}
+
+int block_cache_fini(service_id_t service_id)
+{
+	devcon_t *devcon = devcon_search(service_id);
+	cache_t *cache;
+	int rc;
+
+	if (!devcon)
+		return ENOENT;
+	if (!devcon->cache)
+		return EOK;
+	cache = devcon->cache;
+	
+	/*
+	 * We are expecting to find all blocks for this device handle on the
+	 * free list, i.e. the block reference count should be zero. Do not
+	 * bother with the cache and block locks because we are single-threaded.
+	 */
+	while (!list_empty(&cache->free_list)) {
+		block_t *b = list_get_instance(list_first(&cache->free_list),
+		    block_t, free_link);
+
+		list_remove(&b->free_link);
+		if (b->dirty) {
+			rc = write_blocks(devcon, b->pba, cache->blocks_cluster,
+			    b->data, b->size);
+			if (rc != EOK)
+				return rc;
+		}
+
+		unsigned long key[2] = {
+			LOWER32(b->lba),
+			UPPER32(b->lba)
+		};
+		hash_table_remove(&cache->block_hash, key, 2);
+		
+		free(b->data);
+		free(b);
+	}
+
+	hash_table_destroy(&cache->block_hash);
+	devcon->cache = NULL;
+	free(cache);
+
+	return EOK;
+}
+
+#define CACHE_LO_WATERMARK	10	
+#define CACHE_HI_WATERMARK	20	
+static bool cache_can_grow(cache_t *cache)
+{
+	if (cache->blocks_cached < CACHE_LO_WATERMARK)
+		return true;
+	if (!list_empty(&cache->free_list))
+		return false;
+	return true;
+}
+
+static void block_initialize(block_t *b)
+{
+	fibril_mutex_initialize(&b->lock);
+	b->refcnt = 1;
+	b->dirty = false;
+	b->toxic = false;
+	fibril_rwlock_initialize(&b->contents_lock);
+	link_initialize(&b->free_link);
+	link_initialize(&b->hash_link);
+}
+
+/** Instantiate a block in memory and get a reference to it.
+ *
+ * @param block			Pointer to where the function will store the
+ * 				block pointer on success.
+ * @param service_id		Service ID of the block device.
+ * @param ba			Block address (logical).
+ * @param flags			If BLOCK_FLAGS_NOREAD is specified, block_get()
+ * 				will not read the contents of the block from the
+ *				device.
+ *
+ * @return			EOK on success or a negative error code.
+ */
+int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)
+{
+	devcon_t *devcon;
+	cache_t *cache;
+	block_t *b;
+	link_t *l;
+	unsigned long key[2] = {
+		LOWER32(ba),
+		UPPER32(ba)
+	};
+
+	int rc;
+	
+	devcon = devcon_search(service_id);
+
+	assert(devcon);
+	assert(devcon->cache);
+	
+	cache = devcon->cache;
+
+retry:
+	rc = EOK;
+	b = NULL;
+
+	fibril_mutex_lock(&cache->lock);
+	l = hash_table_find(&cache->block_hash, key);
+	if (l) {
+found:
+		/*
+		 * We found the block in the cache.
+		 */
+		b = hash_table_get_instance(l, block_t, hash_link);
+		fibril_mutex_lock(&b->lock);
+		if (b->refcnt++ == 0)
+			list_remove(&b->free_link);
+		if (b->toxic)
+			rc = EIO;
+		fibril_mutex_unlock(&b->lock);
+		fibril_mutex_unlock(&cache->lock);
+	} else {
+		/*
+		 * The block was not found in the cache.
+		 */
+		if (cache_can_grow(cache)) {
+			/*
+			 * We can grow the cache by allocating new blocks.
+			 * Should the allocation fail, we fail over and try to
+			 * recycle a block from the cache.
+			 */
+			b = malloc(sizeof(block_t));
+			if (!b)
+				goto recycle;
+			b->data = malloc(cache->lblock_size);
+			if (!b->data) {
+				free(b);
+				b = NULL;
+				goto recycle;
+			}
+			cache->blocks_cached++;
+		} else {
+			/*
+			 * Try to recycle a block from the free list.
+			 */
+recycle:
+			if (list_empty(&cache->free_list)) {
+				fibril_mutex_unlock(&cache->lock);
+				rc = ENOMEM;
+				goto out;
+			}
+			l = list_first(&cache->free_list);
+			b = list_get_instance(l, block_t, free_link);
+
+			fibril_mutex_lock(&b->lock);
+			if (b->dirty) {
+				/*
+				 * The block needs to be written back to the
+				 * device before it changes identity. Do this
+				 * while not holding the cache lock so that
+				 * concurrency is not impeded. Also move the
+				 * block to the end of the free list so that we
+				 * do not slow down other instances of
+				 * block_get() draining the free list.
+				 */
+				list_remove(&b->free_link);
+				list_append(&b->free_link, &cache->free_list);
+				fibril_mutex_unlock(&cache->lock);
+				rc = write_blocks(devcon, b->pba,
+				    cache->blocks_cluster, b->data, b->size);
+				if (rc != EOK) {
+					/*
+					 * We did not manage to write the block
+					 * to the device. Keep it around for
+					 * another try. Hopefully, we will grab
+					 * another block next time.
+					 */
+					fibril_mutex_unlock(&b->lock);
+					goto retry;
+				}
+				b->dirty = false;
+				if (!fibril_mutex_trylock(&cache->lock)) {
+					/*
+					 * Somebody is probably racing with us.
+					 * Unlock the block and retry.
+					 */
+					fibril_mutex_unlock(&b->lock);
+					goto retry;
+				}
+				l = hash_table_find(&cache->block_hash, key);
+				if (l) {
+					/*
+					 * Someone else must have already
+					 * instantiated the block while we were
+					 * not holding the cache lock.
+					 * Leave the recycled block on the
+					 * freelist and continue as if we
+					 * found the block of interest during
+					 * the first try.
+					 */
+					fibril_mutex_unlock(&b->lock);
+					goto found;
+				}
+
+			}
+			fibril_mutex_unlock(&b->lock);
+
+			/*
+			 * Unlink the block from the free list and the hash
+			 * table.
+			 */
+			list_remove(&b->free_link);
+			unsigned long temp_key[2] = {
+				LOWER32(b->lba),
+				UPPER32(b->lba)
+			};
+			hash_table_remove(&cache->block_hash, temp_key, 2);
+		}
+
+		block_initialize(b);
+		b->service_id = service_id;
+		b->size = cache->lblock_size;
+		b->lba = ba;
+		b->pba = ba_ltop(devcon, b->lba);
+		hash_table_insert(&cache->block_hash, key, &b->hash_link);
+
+		/*
+		 * Lock the block before releasing the cache lock. Thus we don't
+		 * kill concurrent operations on the cache while doing I/O on
+		 * the block.
+		 */
+		fibril_mutex_lock(&b->lock);
+		fibril_mutex_unlock(&cache->lock);
+
+		if (!(flags & BLOCK_FLAGS_NOREAD)) {
+			/*
+			 * The block contains old or no data. We need to read
+			 * the new contents from the device.
+			 */
+			rc = read_blocks(devcon, b->pba, cache->blocks_cluster,
+			    b->data, cache->lblock_size);
+			if (rc != EOK) 
+				b->toxic = true;
+		} else
+			rc = EOK;
+
+		fibril_mutex_unlock(&b->lock);
+	}
+out:
+	if ((rc != EOK) && b) {
+		assert(b->toxic);
+		(void) block_put(b);
+		b = NULL;
+	}
+	*block = b;
+	return rc;
+}
+
+/** Release a reference to a block.
+ *
+ * If the last reference is dropped, the block is put on the free list.
+ *
+ * @param block		Block of which a reference is to be released.
+ *
+ * @return		EOK on success or a negative error code.
+ */
+int block_put(block_t *block)
+{
+	devcon_t *devcon = devcon_search(block->service_id);
+	cache_t *cache;
+	unsigned blocks_cached;
+	enum cache_mode mode;
+	int rc = EOK;
+
+	assert(devcon);
+	assert(devcon->cache);
+	assert(block->refcnt >= 1);
+
+	cache = devcon->cache;
+
+retry:
+	fibril_mutex_lock(&cache->lock);
+	blocks_cached = cache->blocks_cached;
+	mode = cache->mode;
+	fibril_mutex_unlock(&cache->lock);
+
+	/*
+	 * Determine whether to sync the block. Syncing the block is best done
+	 * when not holding the cache lock as it does not impede concurrency.
+	 * Since the situation may have changed when we unlocked the cache, the
+	 * blocks_cached and mode variables are mere hints. We will recheck the
+	 * conditions later when the cache lock is held again.
+	 */
+	fibril_mutex_lock(&block->lock);
+	if (block->toxic)
+		block->dirty = false;	/* will not write back toxic block */
+	if (block->dirty && (block->refcnt == 1) &&
+	    (blocks_cached > CACHE_HI_WATERMARK || mode != CACHE_MODE_WB)) {
+		rc = write_blocks(devcon, block->pba, cache->blocks_cluster,
+		    block->data, block->size);
+		block->dirty = false;
+	}
+	fibril_mutex_unlock(&block->lock);
+
+	fibril_mutex_lock(&cache->lock);
+	fibril_mutex_lock(&block->lock);
+	if (!--block->refcnt) {
+		/*
+		 * Last reference to the block was dropped. Either free the
+		 * block or put it on the free list. In case of an I/O error,
+		 * free the block.
+		 */
+		if ((cache->blocks_cached > CACHE_HI_WATERMARK) ||
+		    (rc != EOK)) {
+			/*
+			 * Currently there are too many cached blocks or there
+			 * was an I/O error when writing the block back to the
+			 * device.
+			 */
+			if (block->dirty) {
+				/*
+				 * We cannot sync the block while holding the
+				 * cache lock. Release everything and retry.
+				 */
+				block->refcnt++;
+				fibril_mutex_unlock(&block->lock);
+				fibril_mutex_unlock(&cache->lock);
+				goto retry;
+			}
+			/*
+			 * Take the block out of the cache and free it.
+			 */
+			unsigned long key[2] = {
+				LOWER32(block->lba),
+				UPPER32(block->lba)
+			};
+			hash_table_remove(&cache->block_hash, key, 2);
+			fibril_mutex_unlock(&block->lock);
+			free(block->data);
+			free(block);
+			cache->blocks_cached--;
+			fibril_mutex_unlock(&cache->lock);
+			return rc;
+		}
+		/*
+		 * Put the block on the free list.
+		 */
+		if (cache->mode != CACHE_MODE_WB && block->dirty) {
+			/*
+			 * We cannot sync the block while holding the cache
+			 * lock. Release everything and retry.
+			 */
+			block->refcnt++;
+			fibril_mutex_unlock(&block->lock);
+			fibril_mutex_unlock(&cache->lock);
+			goto retry;
+		}
+		list_append(&block->free_link, &cache->free_list);
+	}
+	fibril_mutex_unlock(&block->lock);
+	fibril_mutex_unlock(&cache->lock);
+
+	return rc;
+}
+
+/** Read sequential data from a block device.
+ *
+ * @param service_id	Service ID of the block device.
+ * @param buf		Buffer for holding one block
+ * @param bufpos	Pointer to the first unread valid offset within the
+ * 			communication buffer.
+ * @param buflen	Pointer to the number of unread bytes that are ready in
+ * 			the communication buffer.
+ * @param pos		Device position to be read.
+ * @param dst		Destination buffer.
+ * @param size		Size of the destination buffer.
+ * @param block_size	Block size to be used for the transfer.
+ *
+ * @return		EOK on success or a negative return code on failure.
+ */
+int block_seqread(service_id_t service_id, void *buf, size_t *bufpos,
+    size_t *buflen, aoff64_t *pos, void *dst, size_t size)
+{
+	size_t offset = 0;
+	size_t left = size;
+	size_t block_size;
+	devcon_t *devcon;
+
+	devcon = devcon_search(service_id);
+	assert(devcon);
+	block_size = devcon->pblock_size;
+	
+	while (left > 0) {
+		size_t rd;
+		
+		if (*bufpos + left < *buflen)
+			rd = left;
+		else
+			rd = *buflen - *bufpos;
+		
+		if (rd > 0) {
+			/*
+			 * Copy the contents of the communication buffer to the
+			 * destination buffer.
+			 */
+			memcpy(dst + offset, buf + *bufpos, rd);
+			offset += rd;
+			*bufpos += rd;
+			*pos += rd;
+			left -= rd;
+		}
+		
+		if (*bufpos == *buflen) {
+			/* Refill the communication buffer with a new block. */
+			int rc;
+
+			rc = read_blocks(devcon, *pos / block_size, 1, buf,
+			    devcon->pblock_size);
+			if (rc != EOK) {
+				return rc;
+			}
+			
+			*bufpos = 0;
+			*buflen = block_size;
+		}
+	}
+	
+	return EOK;
+}
+
+/** Read blocks directly from device (bypass cache).
+ *
+ * @param service_id	Service ID of the block device.
+ * @param ba		Address of first block (physical).
+ * @param cnt		Number of blocks.
+ * @param src		Buffer for storing the data.
+ *
+ * @return		EOK on success or negative error code on failure.
+ */
+int block_read_direct(service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)
+{
+	devcon_t *devcon;
+
+	devcon = devcon_search(service_id);
+	assert(devcon);
+
+	return read_blocks(devcon, ba, cnt, buf, devcon->pblock_size * cnt);
+}
+
+/** Write blocks directly to device (bypass cache).
+ *
+ * @param service_id	Service ID of the block device.
+ * @param ba		Address of first block (physical).
+ * @param cnt		Number of blocks.
+ * @param src		The data to be written.
+ *
+ * @return		EOK on success or negative error code on failure.
+ */
+int block_write_direct(service_id_t service_id, aoff64_t ba, size_t cnt,
+    const void *data)
+{
+	devcon_t *devcon;
+
+	devcon = devcon_search(service_id);
+	assert(devcon);
+
+	return write_blocks(devcon, ba, cnt, (void *)data, devcon->pblock_size * cnt);
+}
+
+/** Get device block size.
+ *
+ * @param service_id	Service ID of the block device.
+ * @param bsize		Output block size.
+ *
+ * @return		EOK on success or negative error code on failure.
+ */
+int block_get_bsize(service_id_t service_id, size_t *bsize)
+{
+	devcon_t *devcon;
+
+	devcon = devcon_search(service_id);
+	assert(devcon);
+
+	return bd_get_block_size(devcon->bd, bsize);
+}
+
+/** Get number of blocks on device.
+ *
+ * @param service_id	Service ID of the block device.
+ * @param nblocks	Output number of blocks.
+ *
+ * @return		EOK on success or negative error code on failure.
+ */
+int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks)
+{
+	devcon_t *devcon = devcon_search(service_id);
+	assert(devcon);
+	
+	return bd_get_num_blocks(devcon->bd, nblocks);
+}
+
+/** Read bytes directly from the device (bypass cache)
+ * 
+ * @param service_id	Service ID of the block device.
+ * @param abs_offset	Absolute offset in bytes where to start reading
+ * @param bytes			Number of bytes to read
+ * @param data			Buffer that receives the data
+ * 
+ * @return		EOK on success or negative error code on failure.
+ */
+int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset,
+    size_t bytes, void *data)
+{
+	int rc;
+	size_t phys_block_size;
+	size_t buf_size;
+	void *buffer;
+	aoff64_t first_block;
+	aoff64_t last_block;
+	size_t blocks;
+	size_t offset;
+	
+	rc = block_get_bsize(service_id, &phys_block_size);
+	if (rc != EOK) {
+		return rc;
+	}
+	
+	/* calculate data position and required space */
+	first_block = abs_offset / phys_block_size;
+	offset = abs_offset % phys_block_size;
+	last_block = (abs_offset + bytes - 1) / phys_block_size;
+	blocks = last_block - first_block + 1;
+	buf_size = blocks * phys_block_size;
+	
+	/* read the data into memory */
+	buffer = malloc(buf_size);
+	if (buffer == NULL) {
+		return ENOMEM;
+	}
+	
+	rc = block_read_direct(service_id, first_block, blocks, buffer);
+	if (rc != EOK) {
+		free(buffer);
+		return rc;
+	}
+	
+	/* copy the data from the buffer */
+	memcpy(data, buffer + offset, bytes);
+	free(buffer);
+	
+	return EOK;
+}
+
+/** Get TOC from device.
+ *
+ * @param service_id Service ID of the block device.
+ * @param session    Starting session.
+ *
+ * @return Allocated TOC structure.
+ * @return NULL on failure.
+ *
+ */
+toc_block_t *block_get_toc(service_id_t service_id, uint8_t session)
+{
+	devcon_t *devcon = devcon_search(service_id);
+	toc_block_t *toc = NULL;
+	int rc;
+	
+	assert(devcon);
+	
+	toc = (toc_block_t *) malloc(sizeof(toc_block_t));
+	if (toc == NULL)
+		return NULL;
+	
+	rc = bd_read_toc(devcon->bd, session, toc, sizeof(toc_block_t));
+	if (rc != EOK) {
+		free(toc);
+		return NULL;
+	}
+	
+	return toc;
+}
+
+/** Read blocks from block device.
+ *
+ * @param devcon	Device connection.
+ * @param ba		Address of first block.
+ * @param cnt		Number of blocks.
+ * @param src		Buffer for storing the data.
+ *
+ * @return		EOK on success or negative error code on failure.
+ */
+static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt, void *buf,
+    size_t size)
+{
+	assert(devcon);
+	
+	int rc = bd_read_blocks(devcon->bd, ba, cnt, buf, size);
+	if (rc != EOK) {
+		printf("Error %d reading %zu blocks starting at block %" PRIuOFF64
+		    " from device handle %" PRIun "\n", rc, cnt, ba,
+		    devcon->service_id);
+#ifndef NDEBUG
+		stacktrace_print();
+#endif
+	}
+	
+	return rc;
+}
+
+/** Write block to block device.
+ *
+ * @param devcon	Device connection.
+ * @param ba		Address of first block.
+ * @param cnt		Number of blocks.
+ * @param src		Buffer containing the data to write.
+ *
+ * @return		EOK on success or negative error code on failure.
+ */
+static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt, void *data,
+    size_t size)
+{
+	assert(devcon);
+	
+	int rc = bd_write_blocks(devcon->bd, ba, cnt, data, size);
+	if (rc != EOK) {
+		printf("Error %d writing %zu blocks starting at block %" PRIuOFF64
+		    " to device handle %" PRIun "\n", rc, cnt, ba, devcon->service_id);
+#ifndef NDEBUG
+		stacktrace_print();
+#endif
+	}
+	
+	return rc;
+}
+
+/** Convert logical block address to physical block address. */
+static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba)
+{
+	assert(devcon->cache != NULL);
+	return lba * devcon->cache->blocks_cluster;
+}
+
+/** @}
+ */
Index: uspace/lib/block/block.h
===================================================================
--- uspace/lib/block/block.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
+++ uspace/lib/block/block.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -0,0 +1,137 @@
+/*
+ * Copyright (c) 2008 Jakub Jermar
+ * Copyright (c) 2008 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 libblock 
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#ifndef LIBBLOCK_LIBBLOCK_H_
+#define LIBBLOCK_LIBBLOCK_H_
+
+#include <stdint.h>
+#include <async.h>
+#include "../../srv/vfs/vfs.h"
+#include <fibril_synch.h>
+#include <adt/hash_table.h>
+#include <adt/list.h>
+
+/*
+ * Flags that can be used with block_get().
+ */
+
+/** 
+ * This macro is a symbolic value for situations where no special flags are
+ * needed.
+ */
+#define BLOCK_FLAGS_NONE	0
+
+/**
+ * When the client of block_get() intends to overwrite the current contents of
+ * the block, this flag is used to avoid the unnecessary read.
+ */
+#define BLOCK_FLAGS_NOREAD	1
+
+typedef struct block {
+	/** Mutex protecting the reference count. */
+	fibril_mutex_t lock;
+	/** Number of references to the block_t structure. */
+	unsigned refcnt;
+	/** If true, the block needs to be written back to the block device. */
+	bool dirty;
+	/** If true, the blcok does not contain valid data. */
+	bool toxic;
+	/** Readers / Writer lock protecting the contents of the block. */
+	fibril_rwlock_t contents_lock;
+	/** Service ID of service providing the block device. */
+	service_id_t service_id;
+	/** Logical block address */
+	aoff64_t lba;
+	/** Physical block address */
+	aoff64_t pba;
+	/** Size of the block. */
+	size_t size;
+	/** Link for placing the block into the free block list. */
+	link_t free_link;
+	/** Link for placing the block into the block hash table. */ 
+	link_t hash_link;
+	/** Buffer with the block data. */
+	void *data;
+} block_t;
+
+/** Caching mode */
+enum cache_mode {
+	/** Write-Through */
+	CACHE_MODE_WT,
+	/** Write-Back */
+	CACHE_MODE_WB
+};
+
+typedef struct {
+	uint16_t size;
+	uint8_t first_session;
+	uint8_t last_session;
+	
+	uint8_t res0;
+	uint8_t adr_ctrl;
+	uint8_t first_track;
+	uint8_t res1;
+	
+	uint32_t first_lba;
+} __attribute__((packed)) toc_block_t;
+
+extern int block_init(exch_mgmt_t, service_id_t, size_t);
+extern void block_fini(service_id_t);
+
+extern int block_bb_read(service_id_t, aoff64_t);
+extern void *block_bb_get(service_id_t);
+
+extern int block_cache_init(service_id_t, size_t, unsigned, enum cache_mode);
+extern int block_cache_fini(service_id_t);
+
+extern int block_get(block_t **, service_id_t, aoff64_t, int);
+extern int block_put(block_t *);
+
+extern int block_seqread(service_id_t, void *, size_t *, size_t *, aoff64_t *,
+    void *, size_t);
+
+extern int block_get_bsize(service_id_t, size_t *);
+extern int block_get_nblocks(service_id_t, aoff64_t *);
+extern toc_block_t *block_get_toc(service_id_t, uint8_t);
+extern int block_read_direct(service_id_t, aoff64_t, size_t, void *);
+extern int block_read_bytes_direct(service_id_t, aoff64_t, size_t, void *);
+extern int block_write_direct(service_id_t, aoff64_t, size_t, const void *);
+
+#endif
+
+/** @}
+ */
Index: pace/lib/block/libblock.c
===================================================================
--- uspace/lib/block/libblock.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ 	(revision )
@@ -1,936 +1,0 @@
-/*
- * Copyright (c) 2008 Jakub Jermar
- * Copyright (c) 2008 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 libblock
- * @{
- */
-/**
- * @file
- * @brief
- */
-
-#include "libblock.h"
-#include "../../srv/vfs/vfs.h"
-#include <ipc/loc.h>
-#include <ipc/services.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include <async.h>
-#include <as.h>
-#include <assert.h>
-#include <bd.h>
-#include <fibril_synch.h>
-#include <adt/list.h>
-#include <adt/hash_table.h>
-#include <macros.h>
-#include <mem.h>
-#include <malloc.h>
-#include <stdio.h>
-#include <sys/typefmt.h>
-#include <stacktrace.h>
-
-/** Lock protecting the device connection list */
-static FIBRIL_MUTEX_INITIALIZE(dcl_lock);
-/** Device connection list head. */
-static LIST_INITIALIZE(dcl);
-
-#define CACHE_BUCKETS_LOG2  10
-#define CACHE_BUCKETS       (1 << CACHE_BUCKETS_LOG2)
-
-typedef struct {
-	fibril_mutex_t lock;
-	size_t lblock_size;       /**< Logical block size. */
-	unsigned blocks_cluster;  /**< Physical blocks per block_t */
-	unsigned block_count;     /**< Total number of blocks. */
-	unsigned blocks_cached;   /**< Number of cached blocks. */
-	hash_table_t block_hash;
-	list_t free_list;
-	enum cache_mode mode;
-} cache_t;
-
-typedef struct {
-	link_t link;
-	service_id_t service_id;
-	async_sess_t *sess;
-	bd_t *bd;
-	void *bb_buf;
-	aoff64_t bb_addr;
-	size_t pblock_size;  /**< Physical block size. */
-	cache_t *cache;
-} devcon_t;
-
-static int read_blocks(devcon_t *, aoff64_t, size_t, void *, size_t);
-static int write_blocks(devcon_t *, aoff64_t, size_t, void *, size_t);
-static aoff64_t ba_ltop(devcon_t *, aoff64_t);
-
-static devcon_t *devcon_search(service_id_t service_id)
-{
-	fibril_mutex_lock(&dcl_lock);
-	
-	list_foreach(dcl, cur) {
-		devcon_t *devcon = list_get_instance(cur, devcon_t, link);
-		if (devcon->service_id == service_id) {
-			fibril_mutex_unlock(&dcl_lock);
-			return devcon;
-		}
-	}
-	
-	fibril_mutex_unlock(&dcl_lock);
-	return NULL;
-}
-
-static int devcon_add(service_id_t service_id, async_sess_t *sess,
-    size_t bsize, bd_t *bd)
-{
-	devcon_t *devcon;
-	
-	devcon = malloc(sizeof(devcon_t));
-	if (!devcon)
-		return ENOMEM;
-	
-	link_initialize(&devcon->link);
-	devcon->service_id = service_id;
-	devcon->sess = sess;
-	devcon->bd = bd;
-	devcon->bb_buf = NULL;
-	devcon->bb_addr = 0;
-	devcon->pblock_size = bsize;
-	devcon->cache = NULL;
-	
-	fibril_mutex_lock(&dcl_lock);
-	list_foreach(dcl, cur) {
-		devcon_t *d = list_get_instance(cur, devcon_t, link);
-		if (d->service_id == service_id) {
-			fibril_mutex_unlock(&dcl_lock);
-			free(devcon);
-			return EEXIST;
-		}
-	}
-	list_append(&devcon->link, &dcl);
-	fibril_mutex_unlock(&dcl_lock);
-	return EOK;
-}
-
-static void devcon_remove(devcon_t *devcon)
-{
-	fibril_mutex_lock(&dcl_lock);
-	list_remove(&devcon->link);
-	fibril_mutex_unlock(&dcl_lock);
-}
-
-int block_init(exch_mgmt_t mgmt, service_id_t service_id,
-    size_t comm_size)
-{
-	bd_t *bd;
-
-	async_sess_t *sess = loc_service_connect(mgmt, service_id,
-	    IPC_FLAG_BLOCKING);
-	if (!sess) {
-		return ENOENT;
-	}
-	
-	int rc = bd_open(sess, &bd);
-	if (rc != EOK) {
-		async_hangup(sess);
-		return rc;
-	}
-	
-	size_t bsize;
-	rc = bd_get_block_size(bd, &bsize);
-	if (rc != EOK) {
-		bd_close(bd);
-		async_hangup(sess);
-		return rc;
-	}
-	
-	rc = devcon_add(service_id, sess, bsize, bd);
-	if (rc != EOK) {
-		bd_close(bd);
-		async_hangup(sess);
-		return rc;
-	}
-	
-	return EOK;
-}
-
-void block_fini(service_id_t service_id)
-{
-	devcon_t *devcon = devcon_search(service_id);
-	assert(devcon);
-	
-	if (devcon->cache)
-		(void) block_cache_fini(service_id);
-	
-	devcon_remove(devcon);
-	
-	if (devcon->bb_buf)
-		free(devcon->bb_buf);
-	
-	bd_close(devcon->bd);
-	async_hangup(devcon->sess);
-	
-	free(devcon);
-}
-
-int block_bb_read(service_id_t service_id, aoff64_t ba)
-{
-	void *bb_buf;
-	int rc;
-
-	devcon_t *devcon = devcon_search(service_id);
-	if (!devcon)
-		return ENOENT;
-	if (devcon->bb_buf)
-		return EEXIST;
-	bb_buf = malloc(devcon->pblock_size);
-	if (!bb_buf)
-		return ENOMEM;
-
-	rc = read_blocks(devcon, 0, 1, bb_buf, devcon->pblock_size);
-	if (rc != EOK) {
-	    	free(bb_buf);
-		return rc;
-	}
-
-	devcon->bb_buf = bb_buf;
-	devcon->bb_addr = ba;
-
-	return EOK;
-}
-
-void *block_bb_get(service_id_t service_id)
-{
-	devcon_t *devcon = devcon_search(service_id);
-	assert(devcon);
-	return devcon->bb_buf;
-}
-
-static hash_index_t cache_hash(unsigned long *key)
-{
-	return MERGE_LOUP32(key[0], key[1]) & (CACHE_BUCKETS - 1);
-}
-
-static int cache_compare(unsigned long *key, hash_count_t keys, link_t *item)
-{
-	block_t *b = hash_table_get_instance(item, block_t, hash_link);
-	return b->lba == MERGE_LOUP32(key[0], key[1]);
-}
-
-static void cache_remove_callback(link_t *item)
-{
-}
-
-static hash_table_operations_t cache_ops = {
-	.hash = cache_hash,
-	.compare = cache_compare,
-	.remove_callback = cache_remove_callback
-};
-
-int block_cache_init(service_id_t service_id, size_t size, unsigned blocks,
-    enum cache_mode mode)
-{
-	devcon_t *devcon = devcon_search(service_id);
-	cache_t *cache;
-	if (!devcon)
-		return ENOENT;
-	if (devcon->cache)
-		return EEXIST;
-	cache = malloc(sizeof(cache_t));
-	if (!cache)
-		return ENOMEM;
-	
-	fibril_mutex_initialize(&cache->lock);
-	list_initialize(&cache->free_list);
-	cache->lblock_size = size;
-	cache->block_count = blocks;
-	cache->blocks_cached = 0;
-	cache->mode = mode;
-
-	/* Allow 1:1 or small-to-large block size translation */
-	if (cache->lblock_size % devcon->pblock_size != 0) {
-		free(cache);
-		return ENOTSUP;
-	}
-
-	cache->blocks_cluster = cache->lblock_size / devcon->pblock_size;
-
-	if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 2,
-	    &cache_ops)) {
-		free(cache);
-		return ENOMEM;
-	}
-
-	devcon->cache = cache;
-	return EOK;
-}
-
-int block_cache_fini(service_id_t service_id)
-{
-	devcon_t *devcon = devcon_search(service_id);
-	cache_t *cache;
-	int rc;
-
-	if (!devcon)
-		return ENOENT;
-	if (!devcon->cache)
-		return EOK;
-	cache = devcon->cache;
-	
-	/*
-	 * We are expecting to find all blocks for this device handle on the
-	 * free list, i.e. the block reference count should be zero. Do not
-	 * bother with the cache and block locks because we are single-threaded.
-	 */
-	while (!list_empty(&cache->free_list)) {
-		block_t *b = list_get_instance(list_first(&cache->free_list),
-		    block_t, free_link);
-
-		list_remove(&b->free_link);
-		if (b->dirty) {
-			rc = write_blocks(devcon, b->pba, cache->blocks_cluster,
-			    b->data, b->size);
-			if (rc != EOK)
-				return rc;
-		}
-
-		unsigned long key[2] = {
-			LOWER32(b->lba),
-			UPPER32(b->lba)
-		};
-		hash_table_remove(&cache->block_hash, key, 2);
-		
-		free(b->data);
-		free(b);
-	}
-
-	hash_table_destroy(&cache->block_hash);
-	devcon->cache = NULL;
-	free(cache);
-
-	return EOK;
-}
-
-#define CACHE_LO_WATERMARK	10	
-#define CACHE_HI_WATERMARK	20	
-static bool cache_can_grow(cache_t *cache)
-{
-	if (cache->blocks_cached < CACHE_LO_WATERMARK)
-		return true;
-	if (!list_empty(&cache->free_list))
-		return false;
-	return true;
-}
-
-static void block_initialize(block_t *b)
-{
-	fibril_mutex_initialize(&b->lock);
-	b->refcnt = 1;
-	b->dirty = false;
-	b->toxic = false;
-	fibril_rwlock_initialize(&b->contents_lock);
-	link_initialize(&b->free_link);
-	link_initialize(&b->hash_link);
-}
-
-/** Instantiate a block in memory and get a reference to it.
- *
- * @param block			Pointer to where the function will store the
- * 				block pointer on success.
- * @param service_id		Service ID of the block device.
- * @param ba			Block address (logical).
- * @param flags			If BLOCK_FLAGS_NOREAD is specified, block_get()
- * 				will not read the contents of the block from the
- *				device.
- *
- * @return			EOK on success or a negative error code.
- */
-int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)
-{
-	devcon_t *devcon;
-	cache_t *cache;
-	block_t *b;
-	link_t *l;
-	unsigned long key[2] = {
-		LOWER32(ba),
-		UPPER32(ba)
-	};
-
-	int rc;
-	
-	devcon = devcon_search(service_id);
-
-	assert(devcon);
-	assert(devcon->cache);
-	
-	cache = devcon->cache;
-
-retry:
-	rc = EOK;
-	b = NULL;
-
-	fibril_mutex_lock(&cache->lock);
-	l = hash_table_find(&cache->block_hash, key);
-	if (l) {
-found:
-		/*
-		 * We found the block in the cache.
-		 */
-		b = hash_table_get_instance(l, block_t, hash_link);
-		fibril_mutex_lock(&b->lock);
-		if (b->refcnt++ == 0)
-			list_remove(&b->free_link);
-		if (b->toxic)
-			rc = EIO;
-		fibril_mutex_unlock(&b->lock);
-		fibril_mutex_unlock(&cache->lock);
-	} else {
-		/*
-		 * The block was not found in the cache.
-		 */
-		if (cache_can_grow(cache)) {
-			/*
-			 * We can grow the cache by allocating new blocks.
-			 * Should the allocation fail, we fail over and try to
-			 * recycle a block from the cache.
-			 */
-			b = malloc(sizeof(block_t));
-			if (!b)
-				goto recycle;
-			b->data = malloc(cache->lblock_size);
-			if (!b->data) {
-				free(b);
-				b = NULL;
-				goto recycle;
-			}
-			cache->blocks_cached++;
-		} else {
-			/*
-			 * Try to recycle a block from the free list.
-			 */
-recycle:
-			if (list_empty(&cache->free_list)) {
-				fibril_mutex_unlock(&cache->lock);
-				rc = ENOMEM;
-				goto out;
-			}
-			l = list_first(&cache->free_list);
-			b = list_get_instance(l, block_t, free_link);
-
-			fibril_mutex_lock(&b->lock);
-			if (b->dirty) {
-				/*
-				 * The block needs to be written back to the
-				 * device before it changes identity. Do this
-				 * while not holding the cache lock so that
-				 * concurrency is not impeded. Also move the
-				 * block to the end of the free list so that we
-				 * do not slow down other instances of
-				 * block_get() draining the free list.
-				 */
-				list_remove(&b->free_link);
-				list_append(&b->free_link, &cache->free_list);
-				fibril_mutex_unlock(&cache->lock);
-				rc = write_blocks(devcon, b->pba,
-				    cache->blocks_cluster, b->data, b->size);
-				if (rc != EOK) {
-					/*
-					 * We did not manage to write the block
-					 * to the device. Keep it around for
-					 * another try. Hopefully, we will grab
-					 * another block next time.
-					 */
-					fibril_mutex_unlock(&b->lock);
-					goto retry;
-				}
-				b->dirty = false;
-				if (!fibril_mutex_trylock(&cache->lock)) {
-					/*
-					 * Somebody is probably racing with us.
-					 * Unlock the block and retry.
-					 */
-					fibril_mutex_unlock(&b->lock);
-					goto retry;
-				}
-				l = hash_table_find(&cache->block_hash, key);
-				if (l) {
-					/*
-					 * Someone else must have already
-					 * instantiated the block while we were
-					 * not holding the cache lock.
-					 * Leave the recycled block on the
-					 * freelist and continue as if we
-					 * found the block of interest during
-					 * the first try.
-					 */
-					fibril_mutex_unlock(&b->lock);
-					goto found;
-				}
-
-			}
-			fibril_mutex_unlock(&b->lock);
-
-			/*
-			 * Unlink the block from the free list and the hash
-			 * table.
-			 */
-			list_remove(&b->free_link);
-			unsigned long temp_key[2] = {
-				LOWER32(b->lba),
-				UPPER32(b->lba)
-			};
-			hash_table_remove(&cache->block_hash, temp_key, 2);
-		}
-
-		block_initialize(b);
-		b->service_id = service_id;
-		b->size = cache->lblock_size;
-		b->lba = ba;
-		b->pba = ba_ltop(devcon, b->lba);
-		hash_table_insert(&cache->block_hash, key, &b->hash_link);
-
-		/*
-		 * Lock the block before releasing the cache lock. Thus we don't
-		 * kill concurrent operations on the cache while doing I/O on
-		 * the block.
-		 */
-		fibril_mutex_lock(&b->lock);
-		fibril_mutex_unlock(&cache->lock);
-
-		if (!(flags & BLOCK_FLAGS_NOREAD)) {
-			/*
-			 * The block contains old or no data. We need to read
-			 * the new contents from the device.
-			 */
-			rc = read_blocks(devcon, b->pba, cache->blocks_cluster,
-			    b->data, cache->lblock_size);
-			if (rc != EOK) 
-				b->toxic = true;
-		} else
-			rc = EOK;
-
-		fibril_mutex_unlock(&b->lock);
-	}
-out:
-	if ((rc != EOK) && b) {
-		assert(b->toxic);
-		(void) block_put(b);
-		b = NULL;
-	}
-	*block = b;
-	return rc;
-}
-
-/** Release a reference to a block.
- *
- * If the last reference is dropped, the block is put on the free list.
- *
- * @param block		Block of which a reference is to be released.
- *
- * @return		EOK on success or a negative error code.
- */
-int block_put(block_t *block)
-{
-	devcon_t *devcon = devcon_search(block->service_id);
-	cache_t *cache;
-	unsigned blocks_cached;
-	enum cache_mode mode;
-	int rc = EOK;
-
-	assert(devcon);
-	assert(devcon->cache);
-	assert(block->refcnt >= 1);
-
-	cache = devcon->cache;
-
-retry:
-	fibril_mutex_lock(&cache->lock);
-	blocks_cached = cache->blocks_cached;
-	mode = cache->mode;
-	fibril_mutex_unlock(&cache->lock);
-
-	/*
-	 * Determine whether to sync the block. Syncing the block is best done
-	 * when not holding the cache lock as it does not impede concurrency.
-	 * Since the situation may have changed when we unlocked the cache, the
-	 * blocks_cached and mode variables are mere hints. We will recheck the
-	 * conditions later when the cache lock is held again.
-	 */
-	fibril_mutex_lock(&block->lock);
-	if (block->toxic)
-		block->dirty = false;	/* will not write back toxic block */
-	if (block->dirty && (block->refcnt == 1) &&
-	    (blocks_cached > CACHE_HI_WATERMARK || mode != CACHE_MODE_WB)) {
-		rc = write_blocks(devcon, block->pba, cache->blocks_cluster,
-		    block->data, block->size);
-		block->dirty = false;
-	}
-	fibril_mutex_unlock(&block->lock);
-
-	fibril_mutex_lock(&cache->lock);
-	fibril_mutex_lock(&block->lock);
-	if (!--block->refcnt) {
-		/*
-		 * Last reference to the block was dropped. Either free the
-		 * block or put it on the free list. In case of an I/O error,
-		 * free the block.
-		 */
-		if ((cache->blocks_cached > CACHE_HI_WATERMARK) ||
-		    (rc != EOK)) {
-			/*
-			 * Currently there are too many cached blocks or there
-			 * was an I/O error when writing the block back to the
-			 * device.
-			 */
-			if (block->dirty) {
-				/*
-				 * We cannot sync the block while holding the
-				 * cache lock. Release everything and retry.
-				 */
-				block->refcnt++;
-				fibril_mutex_unlock(&block->lock);
-				fibril_mutex_unlock(&cache->lock);
-				goto retry;
-			}
-			/*
-			 * Take the block out of the cache and free it.
-			 */
-			unsigned long key[2] = {
-				LOWER32(block->lba),
-				UPPER32(block->lba)
-			};
-			hash_table_remove(&cache->block_hash, key, 2);
-			fibril_mutex_unlock(&block->lock);
-			free(block->data);
-			free(block);
-			cache->blocks_cached--;
-			fibril_mutex_unlock(&cache->lock);
-			return rc;
-		}
-		/*
-		 * Put the block on the free list.
-		 */
-		if (cache->mode != CACHE_MODE_WB && block->dirty) {
-			/*
-			 * We cannot sync the block while holding the cache
-			 * lock. Release everything and retry.
-			 */
-			block->refcnt++;
-			fibril_mutex_unlock(&block->lock);
-			fibril_mutex_unlock(&cache->lock);
-			goto retry;
-		}
-		list_append(&block->free_link, &cache->free_list);
-	}
-	fibril_mutex_unlock(&block->lock);
-	fibril_mutex_unlock(&cache->lock);
-
-	return rc;
-}
-
-/** Read sequential data from a block device.
- *
- * @param service_id	Service ID of the block device.
- * @param buf		Buffer for holding one block
- * @param bufpos	Pointer to the first unread valid offset within the
- * 			communication buffer.
- * @param buflen	Pointer to the number of unread bytes that are ready in
- * 			the communication buffer.
- * @param pos		Device position to be read.
- * @param dst		Destination buffer.
- * @param size		Size of the destination buffer.
- * @param block_size	Block size to be used for the transfer.
- *
- * @return		EOK on success or a negative return code on failure.
- */
-int block_seqread(service_id_t service_id, void *buf, size_t *bufpos,
-    size_t *buflen, aoff64_t *pos, void *dst, size_t size)
-{
-	size_t offset = 0;
-	size_t left = size;
-	size_t block_size;
-	devcon_t *devcon;
-
-	devcon = devcon_search(service_id);
-	assert(devcon);
-	block_size = devcon->pblock_size;
-	
-	while (left > 0) {
-		size_t rd;
-		
-		if (*bufpos + left < *buflen)
-			rd = left;
-		else
-			rd = *buflen - *bufpos;
-		
-		if (rd > 0) {
-			/*
-			 * Copy the contents of the communication buffer to the
-			 * destination buffer.
-			 */
-			memcpy(dst + offset, buf + *bufpos, rd);
-			offset += rd;
-			*bufpos += rd;
-			*pos += rd;
-			left -= rd;
-		}
-		
-		if (*bufpos == *buflen) {
-			/* Refill the communication buffer with a new block. */
-			int rc;
-
-			rc = read_blocks(devcon, *pos / block_size, 1, buf,
-			    devcon->pblock_size);
-			if (rc != EOK) {
-				return rc;
-			}
-			
-			*bufpos = 0;
-			*buflen = block_size;
-		}
-	}
-	
-	return EOK;
-}
-
-/** Read blocks directly from device (bypass cache).
- *
- * @param service_id	Service ID of the block device.
- * @param ba		Address of first block (physical).
- * @param cnt		Number of blocks.
- * @param src		Buffer for storing the data.
- *
- * @return		EOK on success or negative error code on failure.
- */
-int block_read_direct(service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)
-{
-	devcon_t *devcon;
-
-	devcon = devcon_search(service_id);
-	assert(devcon);
-
-	return read_blocks(devcon, ba, cnt, buf, devcon->pblock_size * cnt);
-}
-
-/** Write blocks directly to device (bypass cache).
- *
- * @param service_id	Service ID of the block device.
- * @param ba		Address of first block (physical).
- * @param cnt		Number of blocks.
- * @param src		The data to be written.
- *
- * @return		EOK on success or negative error code on failure.
- */
-int block_write_direct(service_id_t service_id, aoff64_t ba, size_t cnt,
-    const void *data)
-{
-	devcon_t *devcon;
-
-	devcon = devcon_search(service_id);
-	assert(devcon);
-
-	return write_blocks(devcon, ba, cnt, (void *)data, devcon->pblock_size * cnt);
-}
-
-/** Get device block size.
- *
- * @param service_id	Service ID of the block device.
- * @param bsize		Output block size.
- *
- * @return		EOK on success or negative error code on failure.
- */
-int block_get_bsize(service_id_t service_id, size_t *bsize)
-{
-	devcon_t *devcon;
-
-	devcon = devcon_search(service_id);
-	assert(devcon);
-
-	return bd_get_block_size(devcon->bd, bsize);
-}
-
-/** Get number of blocks on device.
- *
- * @param service_id	Service ID of the block device.
- * @param nblocks	Output number of blocks.
- *
- * @return		EOK on success or negative error code on failure.
- */
-int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks)
-{
-	devcon_t *devcon = devcon_search(service_id);
-	assert(devcon);
-	
-	return bd_get_num_blocks(devcon->bd, nblocks);
-}
-
-/** Read bytes directly from the device (bypass cache)
- * 
- * @param service_id	Service ID of the block device.
- * @param abs_offset	Absolute offset in bytes where to start reading
- * @param bytes			Number of bytes to read
- * @param data			Buffer that receives the data
- * 
- * @return		EOK on success or negative error code on failure.
- */
-int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset,
-    size_t bytes, void *data)
-{
-	int rc;
-	size_t phys_block_size;
-	size_t buf_size;
-	void *buffer;
-	aoff64_t first_block;
-	aoff64_t last_block;
-	size_t blocks;
-	size_t offset;
-	
-	rc = block_get_bsize(service_id, &phys_block_size);
-	if (rc != EOK) {
-		return rc;
-	}
-	
-	/* calculate data position and required space */
-	first_block = abs_offset / phys_block_size;
-	offset = abs_offset % phys_block_size;
-	last_block = (abs_offset + bytes - 1) / phys_block_size;
-	blocks = last_block - first_block + 1;
-	buf_size = blocks * phys_block_size;
-	
-	/* read the data into memory */
-	buffer = malloc(buf_size);
-	if (buffer == NULL) {
-		return ENOMEM;
-	}
-	
-	rc = block_read_direct(service_id, first_block, blocks, buffer);
-	if (rc != EOK) {
-		free(buffer);
-		return rc;
-	}
-	
-	/* copy the data from the buffer */
-	memcpy(data, buffer + offset, bytes);
-	free(buffer);
-
-	return EOK;
-}
-
-/** Get TOC from device.
- *
- * @param service_id Service ID of the block device.
- * @param session    Starting session.
- *
- * @return Allocated TOC structure.
- * @return NULL on failure.
- *
- */
-toc_block_t *block_get_toc(service_id_t service_id, uint8_t session)
-{
-	devcon_t *devcon = devcon_search(service_id);
-	toc_block_t *toc = NULL;
-	int rc;
-	
-	assert(devcon);
-	
-	toc = (toc_block_t *) malloc(sizeof(toc_block_t));
-	if (toc == NULL)
-		return NULL;
-	
-	rc = bd_read_toc(devcon->bd, session, toc, sizeof(toc_block_t));
-	if (rc != EOK) {
-		free(toc);
-		return NULL;
-	}
-	
-	return toc;
-}
-
-/** Read blocks from block device.
- *
- * @param devcon	Device connection.
- * @param ba		Address of first block.
- * @param cnt		Number of blocks.
- * @param src		Buffer for storing the data.
- *
- * @return		EOK on success or negative error code on failure.
- */
-static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt, void *buf,
-    size_t size)
-{
-	assert(devcon);
-	
-	int rc = bd_read_blocks(devcon->bd, ba, cnt, buf, size);
-	if (rc != EOK) {
-		printf("Error %d reading %zu blocks starting at block %" PRIuOFF64
-		    " from device handle %" PRIun "\n", rc, cnt, ba,
-		    devcon->service_id);
-#ifndef NDEBUG
-		stacktrace_print();
-#endif
-	}
-	
-	return rc;
-}
-
-/** Write block to block device.
- *
- * @param devcon	Device connection.
- * @param ba		Address of first block.
- * @param cnt		Number of blocks.
- * @param src		Buffer containing the data to write.
- *
- * @return		EOK on success or negative error code on failure.
- */
-static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt, void *data,
-    size_t size)
-{
-	assert(devcon);
-	
-	int rc = bd_write_blocks(devcon->bd, ba, cnt, data, size);
-	if (rc != EOK) {
-		printf("Error %d writing %zu blocks starting at block %" PRIuOFF64
-		    " to device handle %" PRIun "\n", rc, cnt, ba, devcon->service_id);
-#ifndef NDEBUG
-		stacktrace_print();
-#endif
-	}
-	
-	return rc;
-}
-
-/** Convert logical block address to physical block address. */
-static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba)
-{
-	assert(devcon->cache != NULL);
-	return lba * devcon->cache->blocks_cluster;
-}
-
-/** @}
- */
Index: pace/lib/block/libblock.h
===================================================================
--- uspace/lib/block/libblock.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ 	(revision )
@@ -1,137 +1,0 @@
-/*
- * Copyright (c) 2008 Jakub Jermar
- * Copyright (c) 2008 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 libblock 
- * @{
- */ 
-/**
- * @file
- */
-
-#ifndef LIBBLOCK_LIBBLOCK_H_
-#define LIBBLOCK_LIBBLOCK_H_
-
-#include <stdint.h>
-#include <async.h>
-#include "../../srv/vfs/vfs.h"
-#include <fibril_synch.h>
-#include <adt/hash_table.h>
-#include <adt/list.h>
-
-/*
- * Flags that can be used with block_get().
- */
-
-/** 
- * This macro is a symbolic value for situations where no special flags are
- * needed.
- */
-#define BLOCK_FLAGS_NONE	0
-
-/**
- * When the client of block_get() intends to overwrite the current contents of
- * the block, this flag is used to avoid the unnecessary read.
- */
-#define BLOCK_FLAGS_NOREAD	1
-
-typedef struct block {
-	/** Mutex protecting the reference count. */
-	fibril_mutex_t lock;
-	/** Number of references to the block_t structure. */
-	unsigned refcnt;
-	/** If true, the block needs to be written back to the block device. */
-	bool dirty;
-	/** If true, the blcok does not contain valid data. */
-	bool toxic;
-	/** Readers / Writer lock protecting the contents of the block. */
-	fibril_rwlock_t contents_lock;
-	/** Service ID of service providing the block device. */
-	service_id_t service_id;
-	/** Logical block address */
-	aoff64_t lba;
-	/** Physical block address */
-	aoff64_t pba;
-	/** Size of the block. */
-	size_t size;
-	/** Link for placing the block into the free block list. */
-	link_t free_link;
-	/** Link for placing the block into the block hash table. */ 
-	link_t hash_link;
-	/** Buffer with the block data. */
-	void *data;
-} block_t;
-
-/** Caching mode */
-enum cache_mode {
-	/** Write-Through */
-	CACHE_MODE_WT,
-	/** Write-Back */
-	CACHE_MODE_WB
-};
-
-typedef struct {
-	uint16_t size;
-	uint8_t first_session;
-	uint8_t last_session;
-	
-	uint8_t res0;
-	uint8_t adr_ctrl;
-	uint8_t first_track;
-	uint8_t res1;
-	
-	uint32_t first_lba;
-} __attribute__((packed)) toc_block_t;
-
-extern int block_init(exch_mgmt_t, service_id_t, size_t);
-extern void block_fini(service_id_t);
-
-extern int block_bb_read(service_id_t, aoff64_t);
-extern void *block_bb_get(service_id_t);
-
-extern int block_cache_init(service_id_t, size_t, unsigned, enum cache_mode);
-extern int block_cache_fini(service_id_t);
-
-extern int block_get(block_t **, service_id_t, aoff64_t, int);
-extern int block_put(block_t *);
-
-extern int block_seqread(service_id_t, void *, size_t *, size_t *, aoff64_t *,
-    void *, size_t);
-
-extern int block_get_bsize(service_id_t, size_t *);
-extern int block_get_nblocks(service_id_t, aoff64_t *);
-extern toc_block_t *block_get_toc(service_id_t, uint8_t);
-extern int block_read_direct(service_id_t, aoff64_t, size_t, void *);
-extern int block_read_bytes_direct(service_id_t, aoff64_t, size_t, void *);
-extern int block_write_direct(service_id_t, aoff64_t, size_t, const void *);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/ext2/libext2_block_group.h
===================================================================
--- uspace/lib/ext2/libext2_block_group.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext2/libext2_block_group.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -37,5 +37,5 @@
 #define LIBEXT2_LIBEXT2_BLOCK_GROUP_H_
 
-#include <libblock.h>
+#include <block.h>
 
 typedef struct ext2_block_group {
Index: uspace/lib/ext2/libext2_directory.h
===================================================================
--- uspace/lib/ext2/libext2_directory.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext2/libext2_directory.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -37,5 +37,5 @@
 #define LIBEXT2_LIBEXT2_DIRECTORY_H_
 
-#include <libblock.h>
+#include <block.h>
 #include "libext2_filesystem.h"
 #include "libext2_inode.h"
Index: uspace/lib/ext2/libext2_filesystem.c
===================================================================
--- uspace/lib/ext2/libext2_filesystem.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext2/libext2_filesystem.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -39,5 +39,5 @@
 #include "libext2_inode.h"
 #include <errno.h>
-#include <libblock.h>
+#include <block.h>
 #include <malloc.h>
 #include <assert.h>
Index: uspace/lib/ext2/libext2_filesystem.h
===================================================================
--- uspace/lib/ext2/libext2_filesystem.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext2/libext2_filesystem.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -37,5 +37,5 @@
 #define LIBEXT2_LIBEXT2_FILESYSTEM_H_
 
-#include <libblock.h>
+#include <block.h>
 #include "libext2_superblock.h"
 #include "libext2_block_group.h"
Index: uspace/lib/ext2/libext2_inode.h
===================================================================
--- uspace/lib/ext2/libext2_inode.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext2/libext2_inode.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -37,5 +37,5 @@
 #define LIBEXT2_LIBEXT2_INODE_H_
 
-#include <libblock.h>
+#include <block.h>
 #include "libext2_superblock.h"
 
Index: uspace/lib/ext2/libext2_superblock.c
===================================================================
--- uspace/lib/ext2/libext2_superblock.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext2/libext2_superblock.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -37,5 +37,5 @@
 #include <errno.h>
 #include <malloc.h>
-#include <libblock.h>
+#include <block.h>
 #include <byteorder.h>
 
Index: uspace/lib/ext2/libext2_superblock.h
===================================================================
--- uspace/lib/ext2/libext2_superblock.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext2/libext2_superblock.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -37,5 +37,5 @@
 #define LIBEXT2_LIBEXT2_SUPERBLOCK_H_
 
-#include <libblock.h>
+#include <block.h>
 
 typedef struct ext2_superblock {
Index: uspace/lib/ext4/libext4_bitmap.c
===================================================================
--- uspace/lib/ext4/libext4_bitmap.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext4/libext4_bitmap.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -36,5 +36,5 @@
 
 #include <errno.h>
-#include <libblock.h>
+#include <block.h>
 #include <sys/types.h>
 #include "libext4.h"
Index: uspace/lib/ext4/libext4_block_group.h
===================================================================
--- uspace/lib/ext4/libext4_block_group.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext4/libext4_block_group.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -34,5 +34,5 @@
 #define LIBEXT4_LIBEXT4_BLOCK_GROUP_H_
 
-#include <libblock.h>
+#include <block.h>
 #include <sys/types.h>
 #include "libext4_types.h"
Index: uspace/lib/ext4/libext4_filesystem.h
===================================================================
--- uspace/lib/ext4/libext4_filesystem.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext4/libext4_filesystem.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -34,5 +34,5 @@
 #define LIBEXT4_LIBEXT4_FILESYSTEM_H_
 
-#include <libblock.h>
+#include <block.h>
 #include "libext4_types.h"
 
Index: uspace/lib/ext4/libext4_inode.c
===================================================================
--- uspace/lib/ext4/libext4_inode.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext4/libext4_inode.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -37,5 +37,5 @@
 #include <byteorder.h>
 #include <errno.h>
-#include <libblock.h>
+#include <block.h>
 #include "libext4.h"
 
Index: uspace/lib/ext4/libext4_inode.h
===================================================================
--- uspace/lib/ext4/libext4_inode.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext4/libext4_inode.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -34,5 +34,5 @@
 #define LIBEXT4_LIBEXT4_INODE_H_
 
-#include <libblock.h>
+#include <block.h>
 #include <sys/types.h>
 #include "libext4_types.h"
Index: uspace/lib/ext4/libext4_superblock.c
===================================================================
--- uspace/lib/ext4/libext4_superblock.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext4/libext4_superblock.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -38,5 +38,5 @@
 #include <byteorder.h>
 #include <errno.h>
-#include <libblock.h>
+#include <block.h>
 #include <malloc.h>
 #include "libext4.h"
Index: uspace/lib/ext4/libext4_superblock.h
===================================================================
--- uspace/lib/ext4/libext4_superblock.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext4/libext4_superblock.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -34,5 +34,5 @@
 #define LIBEXT4_LIBEXT4_SUPERBLOCK_H_
 
-#include <libblock.h>
+#include <block.h>
 #include <sys/types.h>
 #include "libext4_types.h"
Index: uspace/lib/ext4/libext4_types.h
===================================================================
--- uspace/lib/ext4/libext4_types.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/lib/ext4/libext4_types.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -34,5 +34,5 @@
 #define LIBEXT4_LIBEXT4_TYPES_H_
 
-#include <libblock.h>
+#include <block.h>
 
 /*
Index: uspace/srv/bd/gxe_bd/gxe_bd.c
===================================================================
--- uspace/srv/bd/gxe_bd/gxe_bd.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/bd/gxe_bd/gxe_bd.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -127,5 +127,5 @@
 static gxe_bd_t *bd_srv_gxe(bd_srv_t *bd)
 {
-	return (gxe_bd_t *)bd->srvs->sarg;
+	return (gxe_bd_t *) bd->srvs->sarg;
 }
 
Index: uspace/srv/bd/part/guid_part/guid_part.c
===================================================================
--- uspace/srv/bd/part/guid_part/guid_part.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/bd/part/guid_part/guid_part.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -55,5 +55,5 @@
 #include <sys/typefmt.h>
 #include <inttypes.h>
-#include <libblock.h>
+#include <block.h>
 #include <loc.h>
 #include <errno.h>
Index: uspace/srv/bd/part/mbr_part/mbr_part.c
===================================================================
--- uspace/srv/bd/part/mbr_part/mbr_part.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/bd/part/mbr_part/mbr_part.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -65,5 +65,5 @@
 #include <sys/typefmt.h>
 #include <inttypes.h>
-#include <libblock.h>
+#include <block.h>
 #include <errno.h>
 #include <bool.h>
Index: uspace/srv/bd/sata_bd/sata_bd.c
===================================================================
--- uspace/srv/bd/sata_bd/sata_bd.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/bd/sata_bd/sata_bd.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -75,5 +75,5 @@
 static sata_bd_dev_t *bd_srv_sata(bd_srv_t *bd)
 {
-	return (sata_bd_dev_t *)bd->srvs->sarg;
+	return (sata_bd_dev_t *) bd->srvs->sarg;
 }
 
Index: uspace/srv/fs/cdfs/cdfs_ops.c
===================================================================
--- uspace/srv/fs/cdfs/cdfs_ops.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/cdfs/cdfs_ops.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -44,5 +44,5 @@
 #include <libfs.h>
 #include <errno.h>
-#include <libblock.h>
+#include <block.h>
 #include <str.h>
 #include <byteorder.h>
Index: uspace/srv/fs/exfat/exfat_bitmap.c
===================================================================
--- uspace/srv/fs/exfat/exfat_bitmap.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/exfat/exfat_bitmap.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -39,5 +39,5 @@
 #include "../../vfs/vfs.h"
 #include <libfs.h>
-#include <libblock.h>
+#include <block.h>
 #include <errno.h>
 #include <byteorder.h>
Index: uspace/srv/fs/exfat/exfat_directory.c
===================================================================
--- uspace/srv/fs/exfat/exfat_directory.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/exfat/exfat_directory.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -39,5 +39,5 @@
 #include "exfat_directory.h"
 #include "exfat_fat.h"
-#include <libblock.h>
+#include <block.h>
 #include <errno.h>
 #include <byteorder.h>
Index: uspace/srv/fs/exfat/exfat_fat.c
===================================================================
--- uspace/srv/fs/exfat/exfat_fat.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/exfat/exfat_fat.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -42,5 +42,5 @@
 #include "../../vfs/vfs.h"
 #include <libfs.h>
-#include <libblock.h>
+#include <block.h>
 #include <errno.h>
 #include <byteorder.h>
Index: uspace/srv/fs/exfat/exfat_fat.h
===================================================================
--- uspace/srv/fs/exfat/exfat_fat.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/exfat/exfat_fat.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -37,5 +37,5 @@
 #include "../../vfs/vfs.h"
 #include <stdint.h>
-#include <libblock.h>
+#include <block.h>
 
 #define EXFAT_ROOT_IDX		0
Index: uspace/srv/fs/exfat/exfat_ops.c
===================================================================
--- uspace/srv/fs/exfat/exfat_ops.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/exfat/exfat_ops.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -45,5 +45,5 @@
 #include "../../vfs/vfs.h"
 #include <libfs.h>
-#include <libblock.h>
+#include <block.h>
 #include <ipc/services.h>
 #include <ipc/loc.h>
Index: uspace/srv/fs/ext2fs/ext2fs_ops.c
===================================================================
--- uspace/srv/fs/ext2fs/ext2fs_ops.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/ext2fs/ext2fs_ops.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -39,5 +39,5 @@
 #include "../../vfs/vfs.h"
 #include <libfs.h>
-#include <libblock.h>
+#include <block.h>
 #include <libext2.h>
 #include <ipc/services.h>
Index: uspace/srv/fs/fat/fat_directory.c
===================================================================
--- uspace/srv/fs/fat/fat_directory.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/fat/fat_directory.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -38,5 +38,5 @@
 #include "fat_directory.h"
 #include "fat_fat.h"
-#include <libblock.h>
+#include <block.h>
 #include <errno.h>
 #include <byteorder.h>
Index: uspace/srv/fs/fat/fat_fat.c
===================================================================
--- uspace/srv/fs/fat/fat_fat.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/fat/fat_fat.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -42,5 +42,5 @@
 #include "../../vfs/vfs.h"
 #include <libfs.h>
-#include <libblock.h>
+#include <block.h>
 #include <errno.h>
 #include <byteorder.h>
Index: uspace/srv/fs/fat/fat_fat.h
===================================================================
--- uspace/srv/fs/fat/fat_fat.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/fat/fat_fat.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -37,5 +37,5 @@
 #include "../../vfs/vfs.h"
 #include <stdint.h>
-#include <libblock.h>
+#include <block.h>
 
 #define FAT1		0
Index: uspace/srv/fs/fat/fat_ops.c
===================================================================
--- uspace/srv/fs/fat/fat_ops.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/fat/fat_ops.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -43,5 +43,5 @@
 #include "../../vfs/vfs.h"
 #include <libfs.h>
-#include <libblock.h>
+#include <block.h>
 #include <ipc/services.h>
 #include <ipc/loc.h>
Index: uspace/srv/fs/mfs/mfs.h
===================================================================
--- uspace/srv/fs/mfs/mfs.h	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/mfs/mfs.h	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -36,5 +36,5 @@
 #include <minix.h>
 #include <macros.h>
-#include <libblock.h>
+#include <block.h>
 #include <libfs.h>
 #include <adt/list.h>
Index: uspace/srv/fs/tmpfs/tmpfs_dump.c
===================================================================
--- uspace/srv/fs/tmpfs/tmpfs_dump.c	(revision 13c4fe0f11335fa9bae9ef702016fe2e3a748030)
+++ uspace/srv/fs/tmpfs/tmpfs_dump.c	(revision f73b2913a9facbac5079836f6c5bee2148010a56)
@@ -44,5 +44,5 @@
 #include <sys/types.h>
 #include <as.h>
-#include <libblock.h>
+#include <block.h>
 #include <byteorder.h>
 
