Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/Makefile	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -71,4 +71,5 @@
 	generic/device/nic.c \
 	generic/device/pci.c \
+	generic/device/ahci.c \
 	generic/elf/elf_load.c \
 	generic/event.c \
Index: uspace/lib/c/arch/abs32le/_link.ld.in
===================================================================
--- uspace/lib/c/arch/abs32le/_link.ld.in	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/abs32le/_link.ld.in	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -14,12 +14,16 @@
 SECTIONS {
 #ifdef LOADER
+	. = 0x70001000 + SIZEOF_HEADERS;
+	
 	.interp : {
 		*(.interp);
-	} :interp
-	
-	. = 0x70001000 + SIZEOF_HEADERS;
+	} :interp :text
 #else
 	. = 0x1000 + SIZEOF_HEADERS;
 #endif
+	
+	/* Make sure the code is aligned reasonably */
+	. = ALIGN(., 16);
+	
 	.text : {
 		*(.text .text.*);
Index: uspace/lib/c/arch/amd64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/amd64/_link.ld.in	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/amd64/_link.ld.in	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -15,12 +15,16 @@
 SECTIONS {
 #ifdef LOADER
+	. = 0x70001000 + SIZEOF_HEADERS;
+	
 	.interp : {
 		*(.interp);
-	} :interp
-	
-	. = 0x70001000 + SIZEOF_HEADERS;
+	} :interp :text
 #else
 	. = 0x1000 + SIZEOF_HEADERS;
 #endif
+	
+	/* Make sure the code is aligned reasonably */
+	. = ALIGN(., 16);
+	
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/amd64/include/elf_linux.h
===================================================================
--- uspace/lib/c/arch/amd64/include/elf_linux.h	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/amd64/include/elf_linux.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -66,4 +66,16 @@
 	uint64_t rsp;
 	uint64_t ss;
+
+	/*
+	 * The following registers need to be part of elf_regs_t.
+	 * Unfortunately, we don't have any information about them in our
+	 * istate_t.
+	 */
+	uint64_t unused_fs_base;
+	uint64_t unused_gs_base;
+	uint64_t unused_ds;
+	uint64_t unused_es;
+	uint64_t unused_fs;
+	uint64_t unused_gs;
 } elf_regs_t;
 
@@ -91,4 +103,14 @@
 	elf_regs->rsp = istate->rsp;
 	elf_regs->ss = istate->ss;
+
+	/*
+	 * Reset the registers for which there is not enough info in istate_t.
+	 */
+	elf_regs->unused_fs_base = 0;
+	elf_regs->unused_gs_base = 0;
+	elf_regs->unused_ds = 0;
+	elf_regs->unused_es = 0;
+	elf_regs->unused_fs = 0;
+	elf_regs->unused_gs = 0;
 }
 
Index: uspace/lib/c/arch/arm32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/arm32/_link.ld.in	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/arm32/_link.ld.in	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -14,12 +14,16 @@
 SECTIONS {
 #ifdef LOADER
+	. = 0x70001000 + SIZEOF_HEADERS;
+	
 	.interp : {
 		*(.interp);
-	} :interp
-	
-	. = 0x70001000 + SIZEOF_HEADERS;
+	} :interp :text
 #else
 	. = 0x1000 + SIZEOF_HEADERS;
 #endif
+	
+	/* Make sure the code is aligned reasonably */
+	. = ALIGN(., 8);
+	
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/arm32/src/fibril.S
===================================================================
--- uspace/lib/c/arch/arm32/src/fibril.S	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/arm32/src/fibril.S	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -35,5 +35,5 @@
 	stmia r0!, {sp, lr}
 	stmia r0!, {r4-r11}
-
+	
 	# return 1
 	mov r0, #1
@@ -43,6 +43,6 @@
 	ldmia r0!, {sp, lr}
 	ldmia r0!, {r4-r11}
-
-	#return 0
+	
+	# return 0
 	mov r0, #0
 	mov pc, lr
Index: uspace/lib/c/arch/arm32/src/stacktrace_asm.S
===================================================================
--- uspace/lib/c/arch/arm32/src/stacktrace_asm.S	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/arm32/src/stacktrace_asm.S	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -41,4 +41,4 @@
 
 stacktrace_pc_get:
-	mov r0, lr 
+	mov r0, lr
 	mov pc, lr
Index: uspace/lib/c/arch/arm32/src/thread_entry.s
===================================================================
--- uspace/lib/c/arch/arm32/src/thread_entry.s	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/arm32/src/thread_entry.s	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -42,4 +42,4 @@
 	push {fp, ip, lr, pc}
 	sub fp, ip, #4
-
-        b __thread_main
+	
+	b __thread_main
Index: uspace/lib/c/arch/ia32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ia32/_link.ld.in	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/ia32/_link.ld.in	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -19,9 +19,4 @@
 
 SECTIONS {
-#if defined(LOADER) || defined(DLEXE)
-	.interp : {
-		*(.interp);
-	} :interp
-#endif
 #ifdef LOADER
 	. = 0x70001000 + SIZEOF_HEADERS;
@@ -29,4 +24,14 @@
 	. = 0x1000 + SIZEOF_HEADERS;
 #endif
+	
+#if defined(LOADER) || defined(DLEXE)
+	.interp : {
+		*(.interp);
+	} :interp :text
+#endif
+	
+	/* Make sure the code is aligned reasonably */
+	. = ALIGN(., 16);
+	
 	.init : {
 		*(.init);
@@ -37,5 +42,5 @@
 		*(.rodata .rodata.*);
 	} :text
-
+	
 #if defined(SHLIB) || defined(DLEXE)
 	.rel.plt : {
@@ -80,12 +85,13 @@
 #if defined(SHLIB) || defined(DLEXE)
 	.data.rel : {
-                *(.data.rel .data.rel.*);
+		*(.data.rel .data.rel.*);
 	} :data
-
+	
 	.got : {
-                *(.got);
+		*(.got);
 	} :data
+	
 	.got.plt : {
-                *(.got.plt);
+		*(.got.plt);
 	} :data
 #endif
Index: uspace/lib/c/arch/ia64/Makefile.common
===================================================================
--- uspace/lib/c/arch/ia64/Makefile.common	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/ia64/Makefile.common	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -27,5 +27,15 @@
 #
 
-GCC_CFLAGS += -fno-unwind-tables
+#
+# FIXME:
+#
+# The -fno-selective-scheduling and -fno-selective-scheduling2 options
+# should be removed as soon as a bug in GCC concerning unchecked
+# speculative loads is fixed.
+#
+# See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53975 for reference.
+#
+
+GCC_CFLAGS += -fno-unwind-tables -fno-selective-scheduling -fno-selective-scheduling2
 
 ENDIANESS = LE
Index: uspace/lib/c/arch/ia64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ia64/_link.ld.in	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/ia64/_link.ld.in	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -14,18 +14,16 @@
 SECTIONS {
 #ifdef LOADER
+	. = 0x800000000 + SIZEOF_HEADERS;
+	
 	.interp : {
 		*(.interp);
-	} :interp
-	
-	. = 0x800000000 + SIZEOF_HEADERS;
+	} :interp :text
 #else
 	. = 0x4000 + SIZEOF_HEADERS;
 #endif
-	/*
-	 * XXX This is just a work around. Problem: .init section does not
-	 * have the proper alignment.
-	 */
+	
+	/* Make sure the code is aligned reasonably */
 	. = ALIGN(., 16);
-
+	
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/mips32/Makefile.common
===================================================================
--- uspace/lib/c/arch/mips32/Makefile.common	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/mips32/Makefile.common	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -27,5 +27,5 @@
 #
 
-GCC_CFLAGS += -mips3 -mabi=32
+GCC_CFLAGS += -msoft-float -mips3 -mabi=32
 
 ENDIANESS = LE
Index: uspace/lib/c/arch/mips32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/mips32/_link.ld.in	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/mips32/_link.ld.in	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -14,12 +14,16 @@
 SECTIONS {
 #ifdef LOADER
+	. = 0x70004000 + SIZEOF_HEADERS;
+	
 	.interp : {
 		*(.interp);
-	} :interp
-	
-	. = 0x70004000 + SIZEOF_HEADERS;
+	} :interp :text
 #else
 	. = 0x4000 + SIZEOF_HEADERS;
 #endif
+	
+	/* Make sure the code is aligned reasonably */
+	. = ALIGN(., 16);
+	
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/mips32eb/Makefile.common
===================================================================
--- uspace/lib/c/arch/mips32eb/Makefile.common	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/mips32eb/Makefile.common	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -27,5 +27,5 @@
 #
 
-GCC_CFLAGS += -mips3 -mabi=32
+GCC_CFLAGS += -msoft-float -mips3 -mabi=32
 
 ENDIANESS = BE
Index: uspace/lib/c/arch/mips64/Makefile.common
===================================================================
--- uspace/lib/c/arch/mips64/Makefile.common	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/mips64/Makefile.common	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -27,5 +27,5 @@
 #
 
-GCC_CFLAGS += -mips3 -mabi=64
+GCC_CFLAGS += -msoft-float -mips3 -mabi=64
 AFLAGS = -64
 
Index: uspace/lib/c/arch/mips64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/mips64/_link.ld.in	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/mips64/_link.ld.in	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -15,12 +15,16 @@
 SECTIONS {
 #ifdef LOADER
+	. = 0x70004000 + SIZEOF_HEADERS;
+	
 	.interp : {
 		*(.interp);
-	} :interp
-	
-	. = 0x70004000 + SIZEOF_HEADERS;
+	} :interp :text
 #else
 	. = 0x4000 + SIZEOF_HEADERS;
 #endif
+	
+	/* Make sure the code is aligned reasonably */
+	. = ALIGN(., 16);
+	
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/ppc32/_link.ld.in
===================================================================
--- uspace/lib/c/arch/ppc32/_link.ld.in	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/ppc32/_link.ld.in	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -15,12 +15,16 @@
 SECTIONS {
 #ifdef LOADER
+	. = 0x70001000 + SIZEOF_HEADERS;
+	
 	.interp : {
 		*(.interp);
-	} :interp
-	
-	. = 0x70001000 + SIZEOF_HEADERS;
+	} :interp :text
 #else
 	. = 0x1000 + SIZEOF_HEADERS;
 #endif
+	
+	/* Make sure the code is aligned reasonably */
+	. = ALIGN(., 4);
+	
 	.init : {
 		*(.init);
Index: uspace/lib/c/arch/sparc64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/sparc64/_link.ld.in	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/arch/sparc64/_link.ld.in	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -14,12 +14,16 @@
 SECTIONS {
 #ifdef LOADER
+	. = 0x70004000 + SIZEOF_HEADERS;
+	
 	.interp : {
 		*(.interp);
-	} :interp
-	
-	. = 0x70004000 + SIZEOF_HEADERS;
+	} :interp :text
 #else
 	. = 0x4000 + SIZEOF_HEADERS;
 #endif
+	
+	/* Make sure the code is aligned reasonably */
+	. = ALIGN(., 16);
+	
 	.init : {
 		*(.init);
Index: uspace/lib/c/generic/device/ahci.c
===================================================================
--- uspace/lib/c/generic/device/ahci.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
+++ uspace/lib/c/generic/device/ahci.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -0,0 +1,185 @@
+/*
+ * Copyright (c) 2012 Petr Jerman
+ * 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 libc
+ * @{
+ */
+/** @file
+ */
+
+#include <ipc/dev_iface.h>
+#include <assert.h>
+#include <device/ahci.h>
+#include <errno.h>
+#include <async.h>
+#include <ipc/services.h>
+#include <stdio.h>
+#include <as.h>
+
+typedef enum {
+	IPC_M_AHCI_GET_SATA_DEVICE_NAME,
+	IPC_M_AHCI_GET_NUM_BLOCKS,
+	IPC_M_AHCI_GET_BLOCK_SIZE,
+	IPC_M_AHCI_READ_BLOCKS,
+	IPC_M_AHCI_WRITE_BLOCKS,
+} ahci_iface_funcs_t;
+
+#define MAX_NAME_LENGTH  1024
+
+#define LO(ptr) \
+	((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) & 0xffffffff))
+
+#define HI(ptr) \
+	((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) >> 32))
+
+async_sess_t* ahci_get_sess(devman_handle_t funh, char **name)
+{
+	// FIXME: Use a better way than substring match
+	
+	*name = NULL;
+	
+	char devn[MAX_NAME_LENGTH];
+	int rc = devman_fun_get_name(funh, devn, MAX_NAME_LENGTH);
+	if (rc != EOK)
+		return NULL;
+	
+	size_t devn_size = str_size(devn);
+	
+	if ((devn_size > 5) && (str_lcmp(devn, "ahci_", 5) == 0)) {
+		async_sess_t *sess = devman_device_connect(EXCHANGE_PARALLEL,
+		    funh, IPC_FLAG_BLOCKING);
+		
+		if (sess) {
+			*name = str_dup(devn);
+			return sess;
+		}
+	}
+	
+	return NULL;
+}
+
+int ahci_get_sata_device_name(async_sess_t *sess, size_t sata_dev_name_length,
+    char *sata_dev_name)
+{
+	async_exch_t *exch = async_exchange_begin(sess);
+	if (!exch)
+		return EINVAL;
+	
+	aid_t req = async_send_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
+	    IPC_M_AHCI_GET_SATA_DEVICE_NAME, sata_dev_name_length, NULL);
+	
+	async_data_read_start(exch, sata_dev_name, sata_dev_name_length);
+	
+	sysarg_t rc;
+	async_wait_for(req, &rc);
+	
+	return rc;
+}
+
+int ahci_get_num_blocks(async_sess_t *sess, uint64_t *blocks)
+{
+	async_exch_t *exch = async_exchange_begin(sess);
+	if (!exch)
+		return EINVAL;
+	
+	sysarg_t blocks_hi;
+	sysarg_t blocks_lo;
+	int rc = async_req_1_2(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
+	    IPC_M_AHCI_GET_NUM_BLOCKS, &blocks_hi, &blocks_lo);
+	
+	async_exchange_end(exch);
+	
+	if (rc == EOK) {
+		*blocks = (((uint64_t) blocks_hi) << 32)
+		    | (((uint64_t) blocks_lo) & 0xffffffff);
+	}
+	
+	return rc;
+}
+
+int ahci_get_block_size(async_sess_t *sess, size_t *blocks_size)
+{
+	async_exch_t *exch = async_exchange_begin(sess);
+	if (!exch)
+		return EINVAL;
+	
+	sysarg_t bs;
+	int rc = async_req_1_1(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
+	    IPC_M_AHCI_GET_BLOCK_SIZE, &bs);
+	
+	async_exchange_end(exch);
+	
+	if (rc == EOK)
+		*blocks_size = (size_t) bs;
+	
+	return rc;
+}
+
+int ahci_read_blocks(async_sess_t *sess, uint64_t blocknum, size_t count,
+    void *buf)
+{
+	async_exch_t *exch = async_exchange_begin(sess);
+	if (!exch)
+		return EINVAL;
+	
+	aid_t req;
+	req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
+	    IPC_M_AHCI_READ_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
+	
+	async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
+	
+	async_exchange_end(exch);
+	
+	sysarg_t rc;
+	async_wait_for(req, &rc);
+	
+	return rc;
+}
+
+int ahci_write_blocks(async_sess_t *sess, uint64_t blocknum, size_t count,
+    void* buf)
+{
+	async_exch_t *exch = async_exchange_begin(sess);
+	if (!exch)
+		return EINVAL;
+	
+	aid_t req = async_send_4(exch, DEV_IFACE_ID(AHCI_DEV_IFACE),
+	    IPC_M_AHCI_WRITE_BLOCKS, HI(blocknum),  LO(blocknum), count, NULL);
+	
+	async_share_out_start(exch, buf, AS_AREA_READ | AS_AREA_WRITE);
+	
+	async_exchange_end(exch);
+	
+	sysarg_t rc;
+	async_wait_for(req, &rc);
+	
+	return rc;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/generic/malloc.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -109,4 +109,7 @@
 	(((uintptr_t) (area)->end) - sizeof(heap_block_foot_t))
 
+#define AREA_LAST_BLOCK_HEAD(area) \
+	((uintptr_t) BLOCK_HEAD(((heap_block_foot_t *) AREA_LAST_BLOCK_FOOT(area))))
+
 /** Get header in heap block.
  *
@@ -346,8 +349,18 @@
 		return false;
 	
-	/* Add new free block */
-	size_t net_size = (size_t) (end - area->end);
-	if (net_size > 0)
-		block_init(area->end, net_size, true, area);
+	heap_block_head_t *last_head =
+	    (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area);
+	
+	if (last_head->free) {
+		/* Add the new space to the last block. */
+		size_t net_size = (size_t) (end - area->end) + last_head->size;
+		malloc_assert(net_size > 0);
+		block_init(last_head, net_size, true, area);
+	} else {
+		/* Add new free block */
+		size_t net_size = (size_t) (end - area->end);
+		if (net_size > 0)
+			block_init(area->end, net_size, true, area);
+	}
 	
 	/* Update heap area parameters */
@@ -355,27 +368,4 @@
 	
 	return true;
-}
-
-/** Try to enlarge any of the heap areas
- *
- * Should be called only inside the critical section.
- *
- * @param size Gross size of item to allocate (bytes).
- *
- */
-static bool heap_grow(size_t size)
-{
-	if (size == 0)
-		return true;
-	
-	/* First try to enlarge some existing area */
-	for (heap_area_t *area = first_heap_area; area != NULL;
-	    area = area->next) {
-		if (area_grow(area, size))
-			return true;
-	}
-	
-	/* Eventually try to create a new area */
-	return area_create(AREA_OVERHEAD(size));
 }
 
@@ -661,4 +651,50 @@
 }
 
+/** Try to enlarge any of the heap areas.
+ *
+ * If successful, allocate block of the given size in the area.
+ * Should be called only inside the critical section.
+ *
+ * @param size  Gross size of item to allocate (bytes).
+ * @param align Memory address alignment.
+ *
+ * @return Allocated block.
+ * @return NULL on failure.
+ *
+ */
+static void *heap_grow_and_alloc(size_t size, size_t align)
+{
+	if (size == 0)
+		return NULL;
+	
+	/* First try to enlarge some existing area */
+	for (heap_area_t *area = first_heap_area; area != NULL;
+	    area = area->next) {
+		
+		if (area_grow(area, size + align)) {
+			heap_block_head_t *first =
+			    (heap_block_head_t *) AREA_LAST_BLOCK_HEAD(area);
+			
+			void *addr =
+			    malloc_area(area, first, NULL, size, align);
+			malloc_assert(addr != NULL);
+			return addr;
+		}
+	}
+	
+	/* Eventually try to create a new area */
+	if (area_create(AREA_OVERHEAD(size + align))) {
+		heap_block_head_t *first =
+		    (heap_block_head_t *) AREA_FIRST_BLOCK_HEAD(last_heap_area);
+		
+		void *addr =
+		    malloc_area(last_heap_area, first, NULL, size, align);
+		malloc_assert(addr != NULL);
+		return addr;
+	}
+	
+	return NULL;
+}
+
 /** Allocate a memory block
  *
@@ -679,16 +715,22 @@
 	
 	size_t falign = lcm(align, BASE_ALIGN);
-	size_t real_size = GROSS_SIZE(ALIGN_UP(size, falign));
-	
-	bool retry = false;
-	heap_block_head_t *split;
-	
-loop:
+	
+	/* Check for integer overflow. */
+	if (falign < align)
+		return NULL;
+	
+	/*
+	 * The size of the allocated block needs to be naturally
+	 * aligned, because the footer structure also needs to reside
+	 * on a naturally aligned address in order to avoid unaligned
+	 * memory accesses.
+	 */
+	size_t gross_size = GROSS_SIZE(ALIGN_UP(size, BASE_ALIGN));
 	
 	/* Try the next fit approach */
-	split = next_fit;
+	heap_block_head_t *split = next_fit;
 	
 	if (split != NULL) {
-		void *addr = malloc_area(split->area, split, NULL, real_size,
+		void *addr = malloc_area(split->area, split, NULL, gross_size,
 		    falign);
 		
@@ -703,5 +745,5 @@
 		    AREA_FIRST_BLOCK_HEAD(area);
 		
-		void *addr = malloc_area(area, first, split, real_size,
+		void *addr = malloc_area(area, first, split, gross_size,
 		    falign);
 		
@@ -710,13 +752,6 @@
 	}
 	
-	if (!retry) {
-		/* Try to grow the heap space */
-		if (heap_grow(real_size)) {
-			retry = true;
-			goto loop;
-		}
-	}
-	
-	return NULL;
+	/* Finally, try to grow heap space and allocate in the new area. */
+	return heap_grow_and_alloc(gross_size, falign);
 }
 
@@ -731,4 +766,6 @@
 void *calloc(const size_t nmemb, const size_t size)
 {
+	// FIXME: Check for overflow
+	
 	void *block = malloc(nmemb * size);
 	if (block == NULL)
@@ -870,5 +907,5 @@
 	if (addr == NULL)
 		return;
-
+	
 	futex_down(&malloc_futex);
 	
Index: uspace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/generic/str.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -428,12 +428,17 @@
  *
  * Do a char-by-char comparison of two NULL-terminated strings.
- * The strings are considered equal iff they consist of the same
- * characters on the minimum of their lengths.
+ * The strings are considered equal iff their length is equal
+ * and both strings consist of the same sequence of characters.
+ *
+ * A string S1 is less than another string S2 if it has a character with
+ * lower value at the first character position where the strings differ.
+ * If the strings differ in length, the shorter one is treated as if
+ * padded by characters with a value of zero.
  *
  * @param s1 First string to compare.
  * @param s2 Second string to compare.
  *
- * @return 0 if the strings are equal, -1 if first is smaller,
- *         1 if second smaller.
+ * @return 0 if the strings are equal, -1 if the first is less than the second,
+ *         1 if the second is less than the first.
  *
  */
@@ -466,6 +471,14 @@
  *
  * Do a char-by-char comparison of two NULL-terminated strings.
- * The strings are considered equal iff they consist of the same
- * characters on the minimum of their lengths and the length limit.
+ * The strings are considered equal iff
+ * min(str_length(s1), max_len) == min(str_length(s2), max_len)
+ * and both strings consist of the same sequence of characters,
+ * up to max_len characters.
+ *
+ * A string S1 is less than another string S2 if it has a character with
+ * lower value at the first character position where the strings differ.
+ * If the strings differ in length, the shorter one is treated as if
+ * padded by characters with a value of zero. Only the first max_len
+ * characters are considered.
  *
  * @param s1      First string to compare.
@@ -473,6 +486,6 @@
  * @param max_len Maximum number of characters to consider.
  *
- * @return 0 if the strings are equal, -1 if first is smaller,
- *         1 if second smaller.
+ * @return 0 if the strings are equal, -1 if the first is less than the second,
+ *         1 if the second is less than the first.
  *
  */
@@ -508,4 +521,40 @@
 	return 0;
 
+}
+
+/** Test whether p is a prefix of s.
+ *
+ * Do a char-by-char comparison of two NULL-terminated strings
+ * and determine if p is a prefix of s.
+ *
+ * @param s The string in which to look
+ * @param p The string to check if it is a prefix of s
+ *
+ * @return true iff p is prefix of s else false
+ *
+ */
+bool str_test_prefix(const char *s, const char *p)
+{
+	wchar_t c1 = 0;
+	wchar_t c2 = 0;
+	
+	size_t off1 = 0;
+	size_t off2 = 0;
+
+	while (true) {
+		c1 = str_decode(s, &off1, STR_NO_LIMIT);
+		c2 = str_decode(p, &off2, STR_NO_LIMIT);
+		
+		if (c2 == 0)
+			return true;
+
+		if (c1 != c2)
+			return false;
+		
+		if (c1 == 0)
+			break;
+	}
+
+	return false;
 }
 
@@ -1085,5 +1134,5 @@
 		c = (c >= 'a' ? c - 'a' + 10 : (c >= 'A' ? c - 'A' + 10 :
 		    (c <= '9' ? c - '0' : 0xff)));
-		if (c > base) {
+		if (c >= base) {
 			break;
 		}
Index: uspace/lib/c/include/device/ahci.h
===================================================================
--- uspace/lib/c/include/device/ahci.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
+++ uspace/lib/c/include/device/ahci.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2012 Petr Jerman
+ * 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 libc
+ * @{
+ */
+/** @file
+ * @brief AHCI interface definition.
+ */
+
+#ifndef LIBC_DEVICE_AHCI_H_
+#define LIBC_DEVICE_AHCI_H_
+
+#include <async.h>
+#include <devman.h>
+
+extern async_sess_t* ahci_get_sess(devman_handle_t, char **);
+
+extern int ahci_get_sata_device_name(async_sess_t *, size_t, char *);
+extern int ahci_get_num_blocks(async_sess_t *, uint64_t *);
+extern int ahci_get_block_size(async_sess_t *, size_t *);
+extern int ahci_read_blocks(async_sess_t *, uint64_t, size_t, void *);
+extern int ahci_write_blocks(async_sess_t *, uint64_t, size_t, void *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/ipc/dev_iface.h
===================================================================
--- uspace/lib/c/include/ipc/dev_iface.h	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/include/ipc/dev_iface.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -51,4 +51,6 @@
 	/** Interface provided by USB HID devices. */
 	USBHID_DEV_IFACE,
+	/** Interface provided by AHCI devices. */
+	AHCI_DEV_IFACE,
 
 	DEV_IFACE_MAX
Index: uspace/lib/c/include/str.h
===================================================================
--- uspace/lib/c/include/str.h	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/c/include/str.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -79,4 +79,6 @@
 extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
 
+extern bool str_test_prefix(const char *s, const char *p);
+
 extern void str_cpy(char *dest, size_t size, const char *src);
 extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
Index: uspace/lib/clui/tinput.c
===================================================================
--- uspace/lib/clui/tinput.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/clui/tinput.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -601,5 +601,9 @@
 	
 	unsigned int cols = max(1, (ti->con_cols + 1) / (max_length + 1));
-	unsigned int col_width = ti->con_cols / cols;
+	unsigned int padding = 0;
+	if ((cols * max_length) + (cols - 1) < ti->con_cols) {
+		padding = ti->con_cols - (cols * max_length) - (cols - 1);
+	}
+	unsigned int col_width = max_length + padding / cols;
 	unsigned int rows = cnum / cols + ((cnum % cols) != 0);
 	
Index: uspace/lib/drv/Makefile
===================================================================
--- uspace/lib/drv/Makefile	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/drv/Makefile	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -44,5 +44,6 @@
 	generic/remote_pci.c \
 	generic/remote_usbhc.c \
-	generic/remote_usbhid.c
+	generic/remote_usbhid.c \
+	generic/remote_ahci.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/drv/generic/dev_iface.c
===================================================================
--- uspace/lib/drv/generic/dev_iface.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/drv/generic/dev_iface.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -46,4 +46,5 @@
 #include "remote_usbhid.h"
 #include "remote_pci.h"
+#include "remote_ahci.h"
 
 static iface_dipatch_table_t remote_ifaces = {
@@ -55,5 +56,6 @@
 		&remote_usb_iface,
 		&remote_usbhc_iface,
-		&remote_usbhid_iface
+		&remote_usbhid_iface,
+		&remote_ahci_iface
 	}
 };
Index: uspace/lib/drv/generic/remote_ahci.c
===================================================================
--- uspace/lib/drv/generic/remote_ahci.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
+++ uspace/lib/drv/generic/remote_ahci.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -0,0 +1,208 @@
+/*
+  * Copyright (c) 2012 Petr Jerman
+ * 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 libdrv
+ * @{
+ */
+/** @file
+ */
+
+#include <async.h>
+#include <errno.h>
+#include <stdio.h>
+#include "ahci_iface.h"
+#include "ddf/driver.h"
+
+typedef enum {
+	IPC_M_AHCI_GET_SATA_DEVICE_NAME,
+	IPC_M_AHCI_GET_NUM_BLOCKS,
+	IPC_M_AHCI_GET_BLOCK_SIZE,
+	IPC_M_AHCI_READ_BLOCKS,
+	IPC_M_AHCI_WRITE_BLOCKS
+} ahci_iface_funcs_t;
+
+#define LO(ptr) \
+	((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) & 0xffffffff))
+
+#define HI(ptr) \
+	((uint32_t) (((uint64_t) ((uintptr_t) (ptr))) >> 32))
+
+static void remote_ahci_get_sata_device_name(ddf_fun_t *, void *, ipc_callid_t,
+    ipc_call_t *);
+static void remote_ahci_get_num_blocks(ddf_fun_t *, void *, ipc_callid_t,
+    ipc_call_t *);
+static void remote_ahci_get_block_size(ddf_fun_t *, void *, ipc_callid_t,
+    ipc_call_t *);
+static void remote_ahci_read_blocks(ddf_fun_t *, void *, ipc_callid_t,
+    ipc_call_t *);
+static void remote_ahci_write_blocks(ddf_fun_t *, void *, ipc_callid_t,
+    ipc_call_t *);
+
+/** Remote AHCI interface operations. */
+static remote_iface_func_ptr_t remote_ahci_iface_ops [] = {
+	[IPC_M_AHCI_GET_SATA_DEVICE_NAME] = remote_ahci_get_sata_device_name,
+	[IPC_M_AHCI_GET_NUM_BLOCKS] = remote_ahci_get_num_blocks,
+	[IPC_M_AHCI_GET_BLOCK_SIZE] = remote_ahci_get_block_size,
+	[IPC_M_AHCI_READ_BLOCKS] = remote_ahci_read_blocks,
+	[IPC_M_AHCI_WRITE_BLOCKS] = remote_ahci_write_blocks
+};
+
+/** Remote AHCI interface structure.
+ */
+remote_iface_t remote_ahci_iface = {
+	.method_count = sizeof(remote_ahci_iface_ops) /
+	    sizeof(remote_ahci_iface_ops[0]),
+	.methods = remote_ahci_iface_ops
+};
+
+void remote_ahci_get_sata_device_name(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
+	
+	if (ahci_iface->get_sata_device_name == NULL) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+	
+	const size_t sata_dev_name_length =
+	    (size_t) DEV_IPC_GET_ARG1(*call);
+	
+	char* sata_dev_name = malloc(sata_dev_name_length);
+	
+	const int ret = ahci_iface->get_sata_device_name(fun,
+	    sata_dev_name_length, sata_dev_name);
+	
+	size_t real_size;
+	ipc_callid_t cid;
+	if ((async_data_read_receive(&cid, &real_size)) &&
+	    (real_size == sata_dev_name_length))
+		async_data_read_finalize(cid, sata_dev_name, sata_dev_name_length);
+	
+	async_answer_0(callid, ret);
+}
+
+static void remote_ahci_get_num_blocks(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
+	
+	if (ahci_iface->get_num_blocks == NULL) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+	
+	uint64_t blocks;
+	const int ret = ahci_iface->get_num_blocks(fun, &blocks);
+	
+	if (ret != EOK)
+		async_answer_0(callid, ret);
+	else
+		async_answer_2(callid, EOK, HI(blocks), LO(blocks));
+}
+
+static void remote_ahci_get_block_size(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
+	
+	if (ahci_iface->get_block_size == NULL) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+	
+	size_t blocks;
+	const int ret = ahci_iface->get_block_size(fun, &blocks);
+	
+	if (ret != EOK)
+		async_answer_0(callid, ret);
+	else
+		async_answer_1(callid, EOK, blocks);
+}
+
+void remote_ahci_read_blocks(ddf_fun_t *fun, void *iface,
+    ipc_callid_t callid, ipc_call_t *call)
+{
+	const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
+	
+	if (ahci_iface->read_blocks == NULL) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+	
+	size_t maxblock_size;
+	unsigned int flags;
+	
+	ipc_callid_t cid;
+	async_share_out_receive(&cid, &maxblock_size, &flags);
+	
+	void *buf;
+	async_share_out_finalize(cid, &buf);
+	
+	const uint64_t blocknum =
+	    (((uint64_t) (DEV_IPC_GET_ARG1(*call))) << 32) |
+	    (((uint64_t) (DEV_IPC_GET_ARG2(*call))) & 0xffffffff);
+	const size_t cnt = (size_t) DEV_IPC_GET_ARG3(*call);
+	
+	const int ret = ahci_iface->read_blocks(fun, blocknum, cnt, buf);
+	
+	async_answer_0(callid, ret);
+}
+
+void remote_ahci_write_blocks(ddf_fun_t *fun, void *iface, ipc_callid_t callid,
+    ipc_call_t *call)
+{
+	const ahci_iface_t *ahci_iface = (ahci_iface_t *) iface;
+	
+	if (ahci_iface->read_blocks == NULL) {
+		async_answer_0(callid, ENOTSUP);
+		return;
+	}
+	
+	size_t maxblock_size;
+	unsigned int flags;
+	
+	ipc_callid_t cid;
+	async_share_out_receive(&cid, &maxblock_size, &flags);
+	
+	void *buf;
+	async_share_out_finalize(cid, &buf);
+	
+	const uint64_t blocknum =
+	    (((uint64_t)(DEV_IPC_GET_ARG1(*call))) << 32) |
+	    (((uint64_t)(DEV_IPC_GET_ARG2(*call))) & 0xffffffff);
+	const size_t cnt = (size_t) DEV_IPC_GET_ARG3(*call);
+	
+	const int ret = ahci_iface->write_blocks(fun, blocknum, cnt, buf);
+	
+	async_answer_0(callid, ret);
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/drv/generic/remote_usb.c
===================================================================
--- uspace/lib/drv/generic/remote_usb.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/drv/generic/remote_usb.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -56,5 +56,5 @@
 {
 	if (!exch)
-		return EINVAL;
+		return EBADMEM;
 	sysarg_t addr;
 	const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
@@ -65,5 +65,5 @@
 	return ret;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Tell interface number given device can use.
  * @param[in] exch IPC communication exchange
@@ -75,5 +75,5 @@
 {
 	if (!exch)
-		return EINVAL;
+		return EBADMEM;
 	sysarg_t iface_no;
 	const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
@@ -83,5 +83,5 @@
 	return ret;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Tell devman handle of device host controller.
  * @param[in] exch IPC communication exchange
@@ -92,5 +92,5 @@
 {
 	if (!exch)
-		return EINVAL;
+		return EBADMEM;
 	devman_handle_t h;
 	const int ret = async_req_1_1(exch, DEV_IFACE_ID(USB_DEV_IFACE),
@@ -121,5 +121,5 @@
 };
 
-/*----------------------------------------------------------------------------*/
+
 void remote_usb_get_my_address(ddf_fun_t *fun, void *iface,
     ipc_callid_t callid, ipc_call_t *call)
@@ -140,5 +140,5 @@
 	}
 }
-/*----------------------------------------------------------------------------*/
+
 void remote_usb_get_my_interface(ddf_fun_t *fun, void *iface,
     ipc_callid_t callid, ipc_call_t *call)
@@ -159,5 +159,5 @@
 	}
 }
-/*----------------------------------------------------------------------------*/
+
 void remote_usb_get_hc_handle(ddf_fun_t *fun, void *iface,
     ipc_callid_t callid, ipc_call_t *call)
Index: uspace/lib/drv/generic/remote_usbhc.c
===================================================================
--- uspace/lib/drv/generic/remote_usbhc.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/drv/generic/remote_usbhc.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -165,5 +165,5 @@
 {
 	if (!exch || !address)
-		return EINVAL;
+		return EBADMEM;
 	sysarg_t new_address;
 	const int ret = async_req_4_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
@@ -173,19 +173,19 @@
 	return ret;
 }
-/*----------------------------------------------------------------------------*/
+
 int usbhc_bind_address(async_exch_t *exch, usb_address_t address,
     devman_handle_t handle)
 {
 	if (!exch)
-		return EINVAL;
+		return EBADMEM;
 	return async_req_3_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
 	    IPC_M_USBHC_BIND_ADDRESS, address, handle);
 }
-/*----------------------------------------------------------------------------*/
+
 int usbhc_get_handle(async_exch_t *exch, usb_address_t address,
     devman_handle_t *handle)
 {
 	if (!exch)
-		return EINVAL;
+		return EBADMEM;
 	sysarg_t h;
 	const int ret = async_req_2_1(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
@@ -195,13 +195,13 @@
 	return ret;
 }
-/*----------------------------------------------------------------------------*/
+
 int usbhc_release_address(async_exch_t *exch, usb_address_t address)
 {
 	if (!exch)
-		return EINVAL;
+		return EBADMEM;
 	return async_req_2_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
 	    IPC_M_USBHC_RELEASE_ADDRESS, address);
 }
-/*----------------------------------------------------------------------------*/
+
 int usbhc_register_endpoint(async_exch_t *exch, usb_address_t address,
     usb_endpoint_t endpoint, usb_transfer_type_t type,
@@ -209,5 +209,5 @@
 {
 	if (!exch)
-		return EINVAL;
+		return EBADMEM;
 	const usb_target_t target =
 	    {{ .address = address, .endpoint = endpoint }};
@@ -220,23 +220,24 @@
 #undef _PACK2
 }
-/*----------------------------------------------------------------------------*/
+
 int usbhc_unregister_endpoint(async_exch_t *exch, usb_address_t address,
     usb_endpoint_t endpoint, usb_direction_t direction)
 {
 	if (!exch)
-		return EINVAL;
+		return EBADMEM;
 	return async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
 	    IPC_M_USBHC_UNREGISTER_ENDPOINT, address, endpoint, direction);
 }
-/*----------------------------------------------------------------------------*/
+
 int usbhc_read(async_exch_t *exch, usb_address_t address,
     usb_endpoint_t endpoint, uint64_t setup, void *data, size_t size,
     size_t *rec_size)
 {
+	if (!exch)
+		return EBADMEM;
+
 	if (size == 0 && setup == 0)
 		return EOK;
 
-	if (!exch)
-		return EINVAL;
 	const usb_target_t target =
 	    {{ .address = address, .endpoint = endpoint }};
@@ -284,13 +285,14 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 int usbhc_write(async_exch_t *exch, usb_address_t address,
     usb_endpoint_t endpoint, uint64_t setup, const void *data, size_t size)
 {
+	if (!exch)
+		return EBADMEM;
+
 	if (size == 0 && setup == 0)
 		return EOK;
 
-	if (!exch)
-		return EINVAL;
 	const usb_target_t target =
 	    {{ .address = address, .endpoint = endpoint }};
@@ -319,5 +321,5 @@
 	return (int) opening_request_rc;
 }
-/*----------------------------------------------------------------------------*/
+
 
 static void remote_usbhc_request_address(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
@@ -384,5 +386,5 @@
 	return trans;
 }
-/*----------------------------------------------------------------------------*/
+
 void remote_usbhc_request_address(ddf_fun_t *fun, void *iface,
     ipc_callid_t callid, ipc_call_t *call)
@@ -406,5 +408,5 @@
 	}
 }
-/*----------------------------------------------------------------------------*/
+
 void remote_usbhc_bind_address(ddf_fun_t *fun, void *iface,
     ipc_callid_t callid, ipc_call_t *call)
@@ -423,5 +425,5 @@
 	async_answer_0(callid, ret);
 }
-/*----------------------------------------------------------------------------*/
+
 void remote_usbhc_get_handle(ddf_fun_t *fun, void *iface,
     ipc_callid_t callid, ipc_call_t *call)
@@ -444,5 +446,5 @@
 	}
 }
-/*----------------------------------------------------------------------------*/
+
 void remote_usbhc_release_address(ddf_fun_t *fun, void *iface,
     ipc_callid_t callid, ipc_call_t *call)
@@ -460,5 +462,5 @@
 	async_answer_0(callid, ret);
 }
-/*----------------------------------------------------------------------------*/
+
 static void callback_out(ddf_fun_t *fun,
     int outcome, void *arg)
@@ -470,5 +472,5 @@
 	async_transaction_destroy(trans);
 }
-/*----------------------------------------------------------------------------*/
+
 static void callback_in(ddf_fun_t *fun,
     int outcome, size_t actual_size, void *arg)
@@ -494,5 +496,5 @@
 	async_transaction_destroy(trans);
 }
-/*----------------------------------------------------------------------------*/
+
 void remote_usbhc_register_endpoint(ddf_fun_t *fun, void *iface,
     ipc_callid_t callid, ipc_call_t *call)
@@ -594,5 +596,5 @@
 	}
 }
-/*----------------------------------------------------------------------------*/
+
 void remote_usbhc_write(
     ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
Index: uspace/lib/drv/include/ahci_iface.h
===================================================================
--- uspace/lib/drv/include/ahci_iface.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
+++ uspace/lib/drv/include/ahci_iface.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2012 Petr Jerman
+ * 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 libdrv
+ * @addtogroup ahci
+ * @{
+ */
+/** @file
+ * @brief AHCI interface definition.
+ */
+
+#ifndef LIBDRV_AHCI_IFACE_H_
+#define LIBDRV_AHCI_IFACE_H_
+
+#include "ddf/driver.h"
+#include <async.h>
+
+/** AHCI device communication interface. */
+typedef struct {
+	int (*get_sata_device_name)(ddf_fun_t *, size_t, char *);
+	int (*get_num_blocks)(ddf_fun_t *, uint64_t *);
+	int (*get_block_size)(ddf_fun_t *, size_t *);
+	int (*read_blocks)(ddf_fun_t *, uint64_t, size_t, void *);
+	int (*write_blocks)(ddf_fun_t *, uint64_t, size_t, void *);
+} ahci_iface_t;
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/drv/include/remote_ahci.h
===================================================================
--- uspace/lib/drv/include/remote_ahci.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
+++ uspace/lib/drv/include/remote_ahci.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2012 Petr Jerman
+ * 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 libdrv
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBDRV_REMOTE_AHCI_H_
+#define LIBDRV_REMOTE_AHCI_H_
+
+extern remote_iface_t remote_ahci_iface;
+
+#endif
+
+/**
+ * @}
+ */
Index: uspace/lib/usbdev/include/usb/dev/usb_device_connection.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/usb_device_connection.h	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbdev/include/usb/dev/usb_device_connection.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -72,5 +72,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Register endpoint on the device.
  * @param instance device connection structure to use.
@@ -91,5 +91,5 @@
 	    instance->address, ep, type, direction, packet_size, interval);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Unregister endpoint on the device.
  * @param instance device connection structure
@@ -105,5 +105,5 @@
 	    instance->address, ep, dir);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Get data from the device.
  * @param[in] instance device connection structure to use.
@@ -122,5 +122,5 @@
 	    instance->address, ep, setup, data, size, rsize);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Send data to the device.
  * @param instance device connection structure to use.
@@ -138,5 +138,5 @@
 	    instance->address, ep, setup, data, size);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Wrapper for read calls with no setup stage.
  * @param[in] instance device connection structure.
@@ -153,5 +153,5 @@
 	return usb_device_control_read(instance, ep, 0, data, size, real_size);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Wrapper for write calls with no setup stage.
  * @param instance device connection structure.
Index: uspace/lib/usbdev/src/devdrv.c
===================================================================
--- uspace/lib/usbdev/src/devdrv.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbdev/src/devdrv.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -74,5 +74,5 @@
 	return ddf_driver_main(&generic_driver);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Count number of pipes the driver expects.
  *
@@ -87,5 +87,5 @@
 	return count;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Callback when a new device is supposed to be controlled by this driver.
  *
@@ -124,5 +124,5 @@
 	return rc;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Callback when a device is supposed to be removed from the system.
  *
@@ -146,5 +146,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Callback when a device was removed from the system.
  *
@@ -167,5 +167,5 @@
 	return ret;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Destroy existing pipes of a USB device.
  *
@@ -178,5 +178,5 @@
 	dev->pipes_count = 0;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Change interface setting of a device.
  * This function selects new alternate setting of an interface by issuing
Index: uspace/lib/usbdev/src/pipes.c
===================================================================
--- uspace/lib/usbdev/src/pipes.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbdev/src/pipes.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -54,5 +54,5 @@
 	return usb_hc_connection_open(pipe->wire->hc_connection);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Terminate a long transfer on a pipe.
  * @param pipe Pipe where to end the long transfer.
@@ -67,5 +67,5 @@
 	return usb_hc_connection_close(pipe->wire->hc_connection);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Try to clear endpoint halt of default control pipe.
  *
@@ -85,5 +85,5 @@
 	pipe->auto_reset_halt = true;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Request a control read transfer on an endpoint pipe.
  *
@@ -135,5 +135,5 @@
 	return rc;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Request a control write transfer on an endpoint pipe.
  *
@@ -182,5 +182,5 @@
 	return rc;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Request a read (in) transfer on an endpoint pipe.
  *
@@ -227,5 +227,5 @@
 	return rc;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Request a write (out) transfer on an endpoint pipe.
  *
@@ -259,5 +259,5 @@
 	    pipe->endpoint_no, buffer, size);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Initialize USB endpoint pipe.
  *
@@ -287,5 +287,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Initialize USB endpoint pipe as the default zero control pipe.
  *
@@ -307,5 +307,5 @@
 	return rc;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Register endpoint with the host controller.
  *
@@ -323,5 +323,5 @@
 	   pipe->direction, pipe->max_packet_size, interval);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Revert endpoint registration with the host controller.
  *
Index: uspace/lib/usbdev/src/pipesinit.c
===================================================================
--- uspace/lib/usbdev/src/pipesinit.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbdev/src/pipesinit.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -154,5 +154,5 @@
     usb_endpoint_mapping_t *mapping, size_t mapping_count,
     usb_standard_interface_descriptor_t *interface,
-    usb_standard_endpoint_descriptor_t *endpoint,
+    usb_standard_endpoint_descriptor_t *endpoint_desc,
     usb_device_connection_t *wire)
 {
@@ -163,13 +163,13 @@
 
 	/* Actual endpoint number is in bits 0..3 */
-	const usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F;
+	const usb_endpoint_t ep_no = endpoint_desc->endpoint_address & 0x0F;
 
 	const usb_endpoint_description_t description = {
 		/* Endpoint direction is set by bit 7 */
-		.direction = (endpoint->endpoint_address & 128)
+		.direction = (endpoint_desc->endpoint_address & 128)
 		    ? USB_DIRECTION_IN : USB_DIRECTION_OUT,
 		/* Transfer type is in bits 0..2 and
 		 * the enum values corresponds 1:1 */
-		.transfer_type = endpoint->attributes & 3,
+		.transfer_type = endpoint_desc->attributes & 3,
 
 		/* Get interface characteristics. */
@@ -194,5 +194,6 @@
 
 	int rc = usb_pipe_initialize(&ep_mapping->pipe, wire,
-	    ep_no, description.transfer_type, endpoint->max_packet_size,
+	    ep_no, description.transfer_type,
+	    uint16_usb2host(endpoint_desc->max_packet_size),
 	    description.direction);
 	if (rc != EOK) {
@@ -201,5 +202,5 @@
 
 	ep_mapping->present = true;
-	ep_mapping->descriptor = endpoint;
+	ep_mapping->descriptor = endpoint_desc;
 	ep_mapping->interface = interface;
 
Index: uspace/lib/usbdev/src/request.c
===================================================================
--- uspace/lib/usbdev/src/request.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbdev/src/request.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -114,5 +114,5 @@
   * 	(in native endianness).
   * @param actual_data_size Actual size of transfered data
-  * 	(in native endianness).
+  *        (in native endianness).
   * @return Error code.
   * @retval EBADMEM @p pipe is NULL.
@@ -147,7 +147,7 @@
 		    | (request_type << 5) | recipient,
 		.request = request,
-		.value = value,
-		.index = index,
-		.length = (uint16_t) data_size,
+		.value = uint16_host2usb(value),
+		.index = uint16_host2usb(index),
+		.length = uint16_host2usb(data_size),
 	};
 
@@ -375,5 +375,5 @@
 	usb_standard_device_descriptor_t descriptor_tmp;
 	int rc = usb_request_get_descriptor(pipe,
-	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE, 
+	    USB_REQUEST_TYPE_STANDARD, USB_REQUEST_RECIPIENT_DEVICE,
 	    USB_DESCTYPE_DEVICE, 0, 0,
 	    &descriptor_tmp, sizeof(descriptor_tmp),
@@ -435,5 +435,4 @@
 	/* Everything is okay, copy the descriptor. */
 	memcpy(descriptor, &descriptor_tmp, sizeof(descriptor_tmp));
-
 	return EOK;
 }
@@ -495,9 +494,11 @@
 		return ENOENT;
 	}
-	if (bare_config.total_length < sizeof(bare_config)) {
+
+	const size_t total_length = uint16_usb2host(bare_config.total_length);
+	if (total_length < sizeof(bare_config)) {
 		return ELIMIT;
 	}
 
-	void *buffer = malloc(bare_config.total_length);
+	void *buffer = malloc(total_length);
 	if (buffer == NULL) {
 		return ENOMEM;
@@ -506,5 +507,5 @@
 	size_t transferred = 0;
 	rc = usb_request_get_full_configuration_descriptor(pipe, index,
-	    buffer, bare_config.total_length, &transferred);
+	    buffer, total_length, &transferred);
 	if (rc != EOK) {
 		free(buffer);
@@ -512,5 +513,5 @@
 	}
 
-	if (transferred != bare_config.total_length) {
+	if (transferred != total_length) {
 		free(buffer);
 		return ELIMIT;
@@ -522,5 +523,5 @@
 
 	if (descriptor_size != NULL) {
-		*descriptor_size = bare_config.total_length;
+		*descriptor_size = total_length;
 	}
 
Index: uspace/lib/usbhid/include/usb/hid/hid_report_items.h
===================================================================
--- uspace/lib/usbhid/include/usb/hid/hid_report_items.h	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhid/include/usb/hid/hid_report_items.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -38,5 +38,5 @@
 #include <stdint.h>
 
-/*---------------------------------------------------------------------------*/
+
 /*
  * Item prefix
@@ -56,5 +56,5 @@
 #define USB_HID_ITEM_IS_LONG(data)	(data == 0xFE)
 
-/*---------------------------------------------------------------------------*/
+
 /*
  * Extended usage macros
@@ -70,5 +70,5 @@
 #define USB_HID_EXTENDED_USAGE(usage)		(usage & 0xFFFF)
 
-/*---------------------------------------------------------------------------*/
+
 /*
  * Input/Output/Feature Item flags
@@ -142,5 +142,5 @@
 #define USB_HID_ITEM_FLAG_BUFFERED(flags)	((flags & 0x100) == 0x100)
 
-/*---------------------------------------------------------------------------*/
+
 
 /* MAIN ITEMS */
@@ -185,5 +185,5 @@
 #define USB_HID_REPORT_TAG_END_COLLECTION	0xC
 
-/*---------------------------------------------------------------------------*/
+
 
 /* GLOBAL ITEMS */
@@ -272,5 +272,5 @@
 #define USB_HID_REPORT_TAG_POP			0xB
 
-/*---------------------------------------------------------------------------*/
+
 
 /* LOCAL ITEMS */
@@ -347,5 +347,5 @@
 #define USB_HID_REPORT_TAG_DELIMITER		0xA
 
-/*---------------------------------------------------------------------------*/
+
 
 #endif
Index: uspace/lib/usbhid/include/usb/hid/hidpath.h
===================================================================
--- uspace/lib/usbhid/include/usb/hid/hidpath.h	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhid/include/usb/hid/hidpath.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -41,5 +41,5 @@
 
 
-/*---------------------------------------------------------------------------*/
+
 /*
  * Flags of usage paths comparison modes.
@@ -73,5 +73,5 @@
 #define USB_HID_PATH_COMPARE_ANYWHERE		8
 
-/*----------------------------------------------------------------------------*/
+
 /** 
  * Item of usage path structure. Last item of linked list describes one item
@@ -93,5 +93,5 @@
 
 
-/*---------------------------------------------------------------------------*/
+
 /** 
  * USB HID usage path structure.
@@ -112,5 +112,5 @@
 } usb_hid_report_path_t;
 
-/*---------------------------------------------------------------------------*/
+
 usb_hid_report_path_t *usb_hid_report_path(void);
 
Index: uspace/lib/usbhid/include/usb/hid/hidtypes.h
===================================================================
--- uspace/lib/usbhid/include/usb/hid/hidtypes.h	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhid/include/usb/hid/hidtypes.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -39,5 +39,5 @@
 #include <adt/list.h>
 
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -69,5 +69,5 @@
 	(((x) < 0 ) ? ((1 << (size)) + (x)) : (x))
 
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -86,5 +86,5 @@
 } usb_hid_report_type_t;
 
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -111,5 +111,5 @@
 	
 } usb_hid_report_t;
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -135,5 +135,5 @@
 	link_t reports_link;
 } usb_hid_report_description_t;
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -202,5 +202,5 @@
 } usb_hid_report_field_t;
 
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -287,5 +287,5 @@
 	int in_delimiter;
 } usb_hid_report_item_t;
-/*---------------------------------------------------------------------------*/
+
 /**
  * Enum of the keyboard modifiers 
@@ -314,5 +314,5 @@
 	USB_HID_MOD_RGUI
 };
-/*---------------------------------------------------------------------------*/
+
 
 
Index: uspace/lib/usbhid/include/usb/hid/request.h
===================================================================
--- uspace/lib/usbhid/include/usb/hid/request.h	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhid/include/usb/hid/request.h	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -42,5 +42,5 @@
 #include <usb/dev/pipes.h>
 
-/*----------------------------------------------------------------------------*/
+
 
 int usbhid_req_set_report(usb_pipe_t *ctrl_pipe, int iface_no,
@@ -61,5 +61,5 @@
 int usbhid_req_get_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t *duration);
 
-/*----------------------------------------------------------------------------*/
+
 
 #endif /* USB_KBD_HIDREQ_H_ */
Index: uspace/lib/usbhid/src/hiddescriptor.c
===================================================================
--- uspace/lib/usbhid/src/hiddescriptor.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhid/src/hiddescriptor.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -41,5 +41,5 @@
 #include <assert.h>
 
-/*---------------------------------------------------------------------------*/
+
 /*
  * Constants defining current parsing mode for correct parsing of the set of
@@ -61,5 +61,5 @@
 #define INSIDE_DELIMITER_SET	2
 
-/*---------------------------------------------------------------------------*/
+
 	
 /** The new report item flag. Used to determine when the item is completly
@@ -78,5 +78,5 @@
 #define USB_HID_UNKNOWN_TAG		-99
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Checks if given collection path is already present in report structure and
@@ -124,5 +124,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Initialize the report descriptor parser structure
@@ -147,5 +147,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -314,5 +314,5 @@
 	return EOK;
 }
-/*---------------------------------------------------------------------------*/
+
 /**
  * Finds description of report with given report_id and of given type in
@@ -348,5 +348,5 @@
 	return NULL;
 }
-/*---------------------------------------------------------------------------*/
+
 
 /** Parse HID report descriptor.
@@ -536,5 +536,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -871,5 +871,5 @@
 	return EOK;
 }
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -892,5 +892,5 @@
 	return result;
 }
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -941,5 +941,5 @@
 
 }
-/*---------------------------------------------------------------------------*/
+
 
 /**
@@ -972,5 +972,5 @@
 	}
 }
-/*---------------------------------------------------------------------------*/
+
 
 
@@ -1022,5 +1022,5 @@
 	return;
 }
-/*---------------------------------------------------------------------------*/
+
 
 /**
Index: uspace/lib/usbhid/src/hidparser.c
===================================================================
--- uspace/lib/usbhid/src/hidparser.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhid/src/hidparser.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -41,5 +41,5 @@
 #include <assert.h>
 
-/*---------------------------------------------------------------------------*/
+
 /*
  * Data translation private functions
@@ -52,5 +52,5 @@
 	int32_t value);
 
-/*---------------------------------------------------------------------------*/
+
 
 static int usb_pow(int a, int b)
@@ -68,5 +68,5 @@
 	}
 }
-/*---------------------------------------------------------------------------*/
+
 
 /** Returns size of report of specified report id and type in items
@@ -117,5 +117,5 @@
 	}
 }
-/*---------------------------------------------------------------------------*/
+
 
 /** Parse and act upon a HID report.
@@ -192,5 +192,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Translate data from the report as specified in report descriptor item
@@ -274,5 +274,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /* OUTPUT API */
 
@@ -431,5 +431,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Translate given data for putting them into the outoput report
@@ -476,5 +476,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Clones given state table
@@ -497,5 +497,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Function for sequence walking through the report. Returns next field in the
@@ -552,5 +552,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Returns next report_id of report of specified type. If zero is given than
@@ -600,5 +600,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Reset all local items in given state table
Index: uspace/lib/usbhid/src/hidpath.c
===================================================================
--- uspace/lib/usbhid/src/hidpath.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhid/src/hidpath.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -41,5 +41,5 @@
 #include <assert.h>
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Compares two usages if they are same or not or one of the usages is not
@@ -63,5 +63,5 @@
 	((page1 == page2) || (page1 == 0) || (page2 == 0))
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Appends one item (couple of usage_path and usage) into the usage path
@@ -93,5 +93,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Removes last item from the usage path structure
@@ -114,5 +114,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Nulls last item of the usage path structure.
@@ -133,5 +133,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Modifies last item of usage path structure by given usage page or usage
@@ -164,5 +164,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  *
@@ -188,5 +188,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Compares two usage paths structures
@@ -354,5 +354,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Allocates and initializes new usage path structure.
@@ -376,5 +376,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Releases given usage path structure.
@@ -395,5 +395,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Clone content of given usage path to the new one
@@ -441,5 +441,5 @@
 }
 
-/*---------------------------------------------------------------------------*/
+
 /**
  * Sets report id in usage path structure
Index: uspace/lib/usbhid/src/hidreport.c
===================================================================
--- uspace/lib/usbhid/src/hidreport.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhid/src/hidreport.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -50,5 +50,5 @@
 #include <usb/hid/hidreport.h>
 
-static int usb_hid_get_report_descriptor(usb_device_t *dev, 
+static int usb_hid_get_report_descriptor(usb_device_t *dev,
     uint8_t **report_desc, size_t *size)
 {
@@ -69,6 +69,6 @@
 	 * First nested descriptor of the configuration descriptor.
 	 */
-	const uint8_t *d = 
-	    usb_dp_get_nested_descriptor(&parser, &parser_data, 
+	const uint8_t *d =
+	    usb_dp_get_nested_descriptor(&parser, &parser_data,
 	    dev->descriptors.configuration);
 	
@@ -78,5 +78,5 @@
 	int i = 0;
 	while (d != NULL && i < dev->interface_no) {
-		d = usb_dp_get_sibling_descriptor(&parser, &parser_data, 
+		d = usb_dp_get_sibling_descriptor(&parser, &parser_data,
 		    dev->descriptors.configuration, d);
 		++i;
@@ -99,5 +99,5 @@
 	 */
 	while (d != NULL && *(d + 1) != USB_DESCTYPE_HID) {
-		d = usb_dp_get_sibling_descriptor(&parser, &parser_data, 
+		d = usb_dp_get_sibling_descriptor(&parser, &parser_data,
 		    iface_desc, d);
 	}
@@ -114,8 +114,8 @@
 	}
 	
-	usb_standard_hid_descriptor_t *hid_desc = 
+	usb_standard_hid_descriptor_t *hid_desc =
 	    (usb_standard_hid_descriptor_t *)d;
 	
-	uint16_t length =  hid_desc->report_desc_info.length;
+	uint16_t length = uint16_usb2host(hid_desc->report_desc_info.length);
 	size_t actual_size = 0;
 
@@ -161,5 +161,5 @@
 }
 
-/*----------------------------------------------------------------------------*/
+
 
 int usb_hid_process_report_descriptor(usb_device_t *dev, 
Index: uspace/lib/usbhid/src/hidreq.c
===================================================================
--- uspace/lib/usbhid/src/hidreq.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhid/src/hidreq.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -45,5 +45,5 @@
 #include <usb/hid/request.h>
 
-/*----------------------------------------------------------------------------*/
+
 /**
  * Send Set Report request to the HID device.
@@ -97,5 +97,5 @@
 }
 
-/*----------------------------------------------------------------------------*/
+
 /**
  * Send Set Protocol request to the HID device.
@@ -145,5 +145,5 @@
 }
 
-/*----------------------------------------------------------------------------*/
+
 /**
  * Send Set Idle request to the HID device.
@@ -195,5 +195,5 @@
 }
 
-/*----------------------------------------------------------------------------*/
+
 /**
  * Send Get Report request to the HID device.
@@ -251,5 +251,5 @@
 }
 
-/*----------------------------------------------------------------------------*/
+
 /**
  * Send Get Protocol request to the HID device.
@@ -310,5 +310,5 @@
 }
 
-/*----------------------------------------------------------------------------*/
+
 /**
  * Send Get Idle request to the HID device.
@@ -373,5 +373,5 @@
 }
 
-/*----------------------------------------------------------------------------*/
+
 
 /**
Index: uspace/lib/usbhost/src/endpoint.c
===================================================================
--- uspace/lib/usbhost/src/endpoint.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhost/src/endpoint.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -72,5 +72,5 @@
 	return instance;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Properly dispose of endpoint_t structure.
  * @param instance endpoint_t structure.
@@ -84,5 +84,5 @@
 	free(instance);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Set device specific data and hooks.
  * @param instance endpoint_t structure.
@@ -101,5 +101,5 @@
 	fibril_mutex_unlock(&instance->guard);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Clear device specific data and hooks.
  * @param instance endpoint_t structure.
@@ -115,5 +115,5 @@
 	fibril_mutex_unlock(&instance->guard);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Mark the endpoint as active and block access for further fibrils.
  * @param instance endpoint_t structure.
@@ -128,5 +128,5 @@
 	fibril_mutex_unlock(&instance->guard);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Mark the endpoint as inactive and allow access for further fibrils.
  * @param instance endpoint_t structure.
@@ -140,5 +140,5 @@
 	fibril_condvar_signal(&instance->avail);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Get the value of toggle bit.
  * @param instance endpoint_t structure.
@@ -156,5 +156,5 @@
 	return ret;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Set the value of toggle bit.
  * @param instance endpoint_t structure.
Index: uspace/lib/usbhost/src/usb_device_manager.c
===================================================================
--- uspace/lib/usbhost/src/usb_device_manager.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhost/src/usb_device_manager.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -61,5 +61,5 @@
 	return new_address;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Initialize device manager structure.
  *
@@ -82,5 +82,5 @@
 	fibril_mutex_initialize(&instance->guard);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Request USB address.
  * @param instance usb_device_manager
@@ -124,5 +124,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Bind USB address to devman handle.
  *
@@ -156,5 +156,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Release used USB address.
  *
@@ -182,5 +182,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Find USB address associated with the device.
  *
@@ -205,5 +205,5 @@
 	return ENOENT;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Find devman handle and speed assigned to USB address.
  *
Index: uspace/lib/usbhost/src/usb_endpoint_manager.c
===================================================================
--- uspace/lib/usbhost/src/usb_endpoint_manager.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhost/src/usb_endpoint_manager.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -61,5 +61,5 @@
 	    && (address == ep->address);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Get list that holds endpoints for given address.
  * @param instance usb_endpoint_manager structure, non-null.
@@ -73,5 +73,5 @@
 	return &instance->endpoint_lists[addr % ENDPOINT_LIST_COUNT];
 }
-/*----------------------------------------------------------------------------*/
+
 /** Internal search function, works on locked structure.
  * @param instance usb_endpoint_manager structure, non-null.
@@ -97,5 +97,5 @@
 	return NULL;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Calculate bandwidth that needs to be reserved for communication with EP.
  * Calculation follows USB 1.1 specification.
@@ -145,5 +145,5 @@
 	}
 }
-/*----------------------------------------------------------------------------*/
+
 /** Initialize to default state.
  * You need to provide valid bw_count function if you plan to use
@@ -168,5 +168,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Check setup packet data for signs of toggle reset.
  *
@@ -227,5 +227,5 @@
 	}
 }
-/*----------------------------------------------------------------------------*/
+
 /** Register endpoint structure.
  * Checks for duplicates.
@@ -262,5 +262,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Unregister endpoint structure.
  * Checks for duplicates.
@@ -286,5 +286,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Find endpoint_t representing the given communication route.
  * @param instance usb_endpoint_manager, non-null.
@@ -301,5 +301,5 @@
 	return ep;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Create and register new endpoint_t structure.
  * @param instance usb_endpoint_manager structure, non-null.
@@ -364,5 +364,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Unregister and destroy endpoint_t structure representing given route.
  * @param instance usb_endpoint_manager structure, non-null.
@@ -395,5 +395,5 @@
 	return EOK;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Unregister and destroy all endpoints using given address.
  * @param instance usb_endpoint_manager structure, non-null.
Index: uspace/lib/usbhost/src/usb_transfer_batch.c
===================================================================
--- uspace/lib/usbhost/src/usb_transfer_batch.c	(revision bc216a07a86e40d74455b7f4d6fb8f65e195443d)
+++ uspace/lib/usbhost/src/usb_transfer_batch.c	(revision 85d31de9fb7e4a793a91abe63f006b2fd2e81ece)
@@ -96,5 +96,5 @@
 	return instance;
 }
-/*----------------------------------------------------------------------------*/
+
 /** Correctly dispose all used data structures.
  *
@@ -116,5 +116,5 @@
 	free(instance);
 }
-/*----------------------------------------------------------------------------*/
+
 /** Prepare data and call the right callback.
  *
