Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision beb17734651364792b1eac56ccfeb343689a4205)
+++ uspace/Makefile	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -35,4 +35,5 @@
 	lib/libc \
 	lib/libfs \
+	lib/libblock \
 	lib/softint \
 	lib/softfloat \
Index: uspace/lib/libblock/Makefile
===================================================================
--- uspace/lib/libblock/Makefile	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
+++ uspace/lib/libblock/Makefile	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -0,0 +1,66 @@
+#
+# 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.
+#
+
+## Common compiler flags
+#
+
+LIBC_PREFIX = ../libc
+## Setup toolchain
+#
+
+include $(LIBC_PREFIX)/Makefile.toolchain
+
+CFLAGS += -Iinclude
+
+## Sources
+#
+
+SOURCES = \
+	libblock.c
+
+OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
+
+.PHONY: all clean depend
+
+all: libblock.a
+
+-include Makefile.depend
+
+clean:
+	-rm -f libblock.a Makefile.depend
+	find . -name '*.o' -follow -exec rm \{\} \;
+
+depend:
+	-makedepend -f - -- $(DEFS) $(CFLAGS) -- $(SOURCES) > Makefile.depend 2> /dev/null
+
+libblock.a: depend $(OBJECTS)
+	$(AR) rc libblock.a $(OBJECTS)
+
+%.o: %.c
+	$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
Index: uspace/lib/libblock/libblock.c
===================================================================
--- uspace/lib/libblock/libblock.c	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
+++ uspace/lib/libblock/libblock.c	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2008 Jakub Jermar 
+ * Copyright (c) 2008 Martin Decky 
+ * 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 "../../srv/rd/rd.h"
+#include <errno.h>
+#include <async.h>
+#include <ipc/ipc.h>
+#include <as.h>
+#include <assert.h>
+
+/** Read data from a block device.
+ *
+ * @param phone		Phone to be used to communicate with the device.
+ * @param buffer	Communication buffer shared with the device.
+ * @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		True on success, false on failure.
+ */
+bool blockread(int phone, void *buffer, off_t *bufpos, size_t *buflen,
+    off_t *pos, void *dst, size_t size, size_t block_size)
+{
+	off_t offset = 0;
+	size_t left = 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, buffer + *bufpos, rd);
+			offset += rd;
+			*bufpos += rd;
+			*pos += rd;
+			left -= rd;
+		}
+		
+		if (*bufpos == *buflen) {
+			/* Refill the communication buffer with a new block. */
+			ipcarg_t retval;
+			int rc = async_req_2_1(phone, RD_READ_BLOCK,
+			    *pos / block_size, block_size, &retval);
+			if ((rc != EOK) || (retval != EOK))
+				return false;
+			
+			*bufpos = 0;
+			*buflen = block_size;
+		}
+	}
+	
+	return true;
+}
+
+int dev_phone = -1;		/* FIXME */
+void *dev_buffer = NULL;	/* FIXME */
+
+block_t *block_get(dev_handle_t dev_handle, off_t offset, size_t bs)
+{
+	/* FIXME */
+	block_t *b;
+	off_t bufpos = 0;
+	size_t buflen = 0;
+	off_t pos = offset * bs;
+
+	assert(dev_phone != -1);
+	assert(dev_buffer);
+
+	b = malloc(sizeof(block_t));
+	if (!b)
+		return NULL;
+	
+	b->data = malloc(bs);
+	if (!b->data) {
+		free(b);
+		return NULL;
+	}
+	b->size = bs;
+
+	if (!blockread(dev_phone, dev_buffer, &bufpos, &buflen, &pos, b->data,
+	    bs, bs)) {
+		free(b->data);
+		free(b);
+		return NULL;
+	}
+
+	return b;
+}
+
+void block_put(block_t *block)
+{
+	/* FIXME */
+	free(block->data);
+	free(block);
+}
+
+/** @}
+ */
Index: uspace/lib/libblock/libblock.h
===================================================================
--- uspace/lib/libblock/libblock.h	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
+++ uspace/lib/libblock/libblock.h	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2008 Jakub Jermar
+ * Copyright (c) 2008 Martin Decky 
+ * 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 "../../srv/vfs/vfs.h"
+
+typedef struct block {
+	void *data;
+	size_t size;
+	bool dirty;
+} block_t;
+
+extern int dev_phone;		/* FIXME */
+extern void *dev_buffer;	/* FIXME */
+
+extern block_t *block_get(dev_handle_t, off_t, size_t);
+extern void block_put(block_t *);
+
+extern bool blockread(int, void *, off_t *, size_t *, off_t *, void *, size_t,
+    size_t);
+
+#endif
+
+/** @}
+ */
+
Index: uspace/lib/libfs/libfs.c
===================================================================
--- uspace/lib/libfs/libfs.c	(revision beb17734651364792b1eac56ccfeb343689a4205)
+++ uspace/lib/libfs/libfs.c	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -37,5 +37,4 @@
 #include "libfs.h" 
 #include "../../srv/vfs/vfs.h"
-#include "../../srv/rd/rd.h"
 #include <errno.h>
 #include <async.h>
@@ -332,61 +331,4 @@
 }
 
-/** Read data from a block device.
- *
- * @param phone		Phone to be used to communicate with the device.
- * @param buffer	Communication buffer shared with the device.
- * @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		True on success, false on failure.
- */
-bool libfs_blockread(int phone, void *buffer, off_t *bufpos, size_t *buflen,
-    off_t *pos, void *dst, size_t size, size_t block_size)
-{
-	off_t offset = 0;
-	size_t left = 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, buffer + *bufpos, rd);
-			offset += rd;
-			*bufpos += rd;
-			*pos += rd;
-			left -= rd;
-		}
-		
-		if (*bufpos == *buflen) {
-			/* Refill the communication buffer with a new block. */
-			ipcarg_t retval;
-			int rc = async_req_2_1(phone, RD_READ_BLOCK,
-			    *pos / block_size, block_size, &retval);
-			if ((rc != EOK) || (retval != EOK))
-				return false;
-			
-			*bufpos = 0;
-			*buflen = block_size;
-		}
-	}
-	
-	return true;
-}
-
 /** @}
  */
Index: uspace/lib/libfs/libfs.h
===================================================================
--- uspace/lib/libfs/libfs.h	(revision beb17734651364792b1eac56ccfeb343689a4205)
+++ uspace/lib/libfs/libfs.h	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -70,7 +70,4 @@
 extern void libfs_lookup(libfs_ops_t *, fs_handle_t, ipc_callid_t, ipc_call_t *);
 
-extern bool libfs_blockread(int, void *, off_t *, size_t *, off_t *, void *,
-    size_t, size_t);
-
 #endif
 
Index: uspace/srv/fs/fat/Makefile
===================================================================
--- uspace/srv/fs/fat/Makefile	(revision beb17734651364792b1eac56ccfeb343689a4205)
+++ uspace/srv/fs/fat/Makefile	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -32,10 +32,14 @@
 LIBC_PREFIX = ../../../lib/libc
 LIBFS_PREFIX = ../../../lib/libfs
+LIBBLOCK_PREFIX = ../../../lib/libblock
 SOFTINT_PREFIX = ../../../lib/softint
 include $(LIBC_PREFIX)/Makefile.toolchain
 
-CFLAGS += -I $(LIBFS_PREFIX)
+CFLAGS += -I $(LIBFS_PREFIX) -I $(LIBBLOCK_PREFIX)
 
-LIBS = $(LIBC_PREFIX)/libc.a $(LIBFS_PREFIX)/libfs.a
+LIBS = \
+	$(LIBC_PREFIX)/libc.a \
+	$(LIBFS_PREFIX)/libfs.a \
+	$(LIBBLOCK_PREFIX)/libblock.a
 
 ## Sources
Index: uspace/srv/fs/fat/fat.h
===================================================================
--- uspace/srv/fs/fat/fat.h	(revision beb17734651364792b1eac56ccfeb343689a4205)
+++ uspace/srv/fs/fat/fat.h	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -198,14 +198,4 @@
 } fat_node_t;
 
-/* TODO move somewhere else */
-typedef struct block {
-	void *data;
-	size_t size;
-	bool dirty;
-} block_t;
-
-extern block_t *block_get(dev_handle_t, off_t, size_t);
-extern void block_put(block_t *);
-
 extern fs_reg_t fat_reg;
 
Index: uspace/srv/fs/fat/fat_fat.c
===================================================================
--- uspace/srv/fs/fat/fat_fat.c	(revision beb17734651364792b1eac56ccfeb343689a4205)
+++ uspace/srv/fs/fat/fat_fat.c	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -41,4 +41,5 @@
 #include "../../vfs/vfs.h"
 #include <libfs.h>
+#include <libblock.h>
 #include <errno.h>
 #include <byteorder.h>
Index: uspace/srv/fs/fat/fat_ops.c
===================================================================
--- uspace/srv/fs/fat/fat_ops.c	(revision beb17734651364792b1eac56ccfeb343689a4205)
+++ uspace/srv/fs/fat/fat_ops.c	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -41,4 +41,5 @@
 #include "../../vfs/vfs.h"
 #include <libfs.h>
+#include <libblock.h>
 #include <ipc/ipc.h>
 #include <ipc/services.h>
@@ -60,46 +61,4 @@
 /** List of cached free FAT nodes. */
 static LIST_INITIALIZE(ffn_head);
-
-static int dev_phone = -1;		/* FIXME */
-static void *dev_buffer = NULL;		/* FIXME */
-
-block_t *block_get(dev_handle_t dev_handle, off_t offset, size_t bs)
-{
-	/* FIXME */
-	block_t *b;
-	off_t bufpos = 0;
-	size_t buflen = 0;
-	off_t pos = offset * bs;
-
-	assert(dev_phone != -1);
-	assert(dev_buffer);
-
-	b = malloc(sizeof(block_t));
-	if (!b)
-		return NULL;
-	
-	b->data = malloc(bs);
-	if (!b->data) {
-		free(b);
-		return NULL;
-	}
-	b->size = bs;
-
-	if (!libfs_blockread(dev_phone, dev_buffer, &bufpos, &buflen, &pos,
-	    b->data, bs, bs)) {
-		free(b->data);
-		free(b);
-		return NULL;
-	}
-
-	return b;
-}
-
-void block_put(block_t *block)
-{
-	/* FIXME */
-	free(block->data);
-	free(block);
-}
 
 static void fat_node_initialize(fat_node_t *node)
Index: uspace/srv/fs/tmpfs/Makefile
===================================================================
--- uspace/srv/fs/tmpfs/Makefile	(revision beb17734651364792b1eac56ccfeb343689a4205)
+++ uspace/srv/fs/tmpfs/Makefile	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -32,10 +32,14 @@
 LIBC_PREFIX = ../../../lib/libc
 LIBFS_PREFIX = ../../../lib/libfs
+LIBBLOCK_PREFIX = ../../../lib/libblock
 SOFTINT_PREFIX = ../../../lib/softint
 include $(LIBC_PREFIX)/Makefile.toolchain
 
-CFLAGS += -I $(LIBFS_PREFIX)
+CFLAGS += -I $(LIBFS_PREFIX) -I $(LIBBLOCK_PREFIX)
 
-LIBS = $(LIBC_PREFIX)/libc.a $(LIBFS_PREFIX)/libfs.a
+LIBS = \
+	$(LIBC_PREFIX)/libc.a \
+	$(LIBFS_PREFIX)/libfs.a \
+	$(LIBBLOCK_PREFIX)/libblock.a
 
 ## Sources
Index: uspace/srv/fs/tmpfs/tmpfs_dump.c
===================================================================
--- uspace/srv/fs/tmpfs/tmpfs_dump.c	(revision beb17734651364792b1eac56ccfeb343689a4205)
+++ uspace/srv/fs/tmpfs/tmpfs_dump.c	(revision fc840d9e1c7b2c78263d76042faa123712a5bb75)
@@ -46,5 +46,5 @@
 #include <sys/types.h>
 #include <as.h>
-#include <libfs.h>
+#include <libblock.h>
 #include <ipc/services.h>
 #include <ipc/devmap.h>
@@ -71,5 +71,5 @@
 		uint32_t size;
 		
-		if (!libfs_blockread(phone, block, bufpos, buflen, pos, &entry,
+		if (!blockread(phone, block, bufpos, buflen, pos, &entry,
 		    sizeof(entry), TMPFS_BLOCK_SIZE))
 			return false;
@@ -91,6 +91,6 @@
 			}
 			
-			if (!libfs_blockread(phone, block, bufpos, buflen, pos,
-			    fname, entry.len, TMPFS_BLOCK_SIZE)) {
+			if (!blockread(phone, block, bufpos, buflen, pos, fname,
+			    entry.len, TMPFS_BLOCK_SIZE)) {
 				ops->destroy((void *) node);
 				free(fname);
@@ -106,6 +106,6 @@
 			free(fname);
 			
-			if (!libfs_blockread(phone, block, bufpos, buflen, pos,
-			    &size, sizeof(size), TMPFS_BLOCK_SIZE))
+			if (!blockread(phone, block, bufpos, buflen, pos, &size,
+			    sizeof(size), TMPFS_BLOCK_SIZE))
 				return false;
 			
@@ -117,5 +117,5 @@
 			
 			node->size = size;
-			if (!libfs_blockread(phone, block, bufpos, buflen, pos,
+			if (!blockread(phone, block, bufpos, buflen, pos,
 			    node->data, size, TMPFS_BLOCK_SIZE))
 				return false;
@@ -133,6 +133,6 @@
 			}
 			
-			if (!libfs_blockread(phone, block, bufpos, buflen, pos,
-			    fname, entry.len, TMPFS_BLOCK_SIZE)) {
+			if (!blockread(phone, block, bufpos, buflen, pos, fname,
+			    entry.len, TMPFS_BLOCK_SIZE)) {
 				ops->destroy((void *) node);
 				free(fname);
@@ -188,5 +188,5 @@
 	
 	char tag[6];
-	if (!libfs_blockread(phone, block, &bufpos, &buflen, &pos, tag, 5,
+	if (!blockread(phone, block, &bufpos, &buflen, &pos, tag, 5,
 	    TMPFS_BLOCK_SIZE))
 		goto error;
