Index: uspace/drv/ns8250/ns8250.c
===================================================================
--- uspace/drv/ns8250/ns8250.c	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/drv/ns8250/ns8250.c	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -123,5 +123,5 @@
 static void delete_ns8250_dev_data(ns8250_dev_data_t *data)
 {
-	if (NULL != data)
+	if (data != NULL)
 		free(data);
 }
@@ -251,5 +251,5 @@
 static void ns8250_dev_cleanup(device_t *dev)
 {
-	if (NULL != dev->driver_data) {
+	if (dev->driver_data != NULL) {
 		delete_ns8250_dev_data((ns8250_dev_data_t*) dev->driver_data);
 		dev->driver_data = NULL;
@@ -332,5 +332,5 @@
 	/* Allocate driver data for the device. */
 	ns8250_dev_data_t *data = create_ns8250_dev_data();
-	if (NULL == data)
+	if (data == NULL)
 		return ENOMEM;
 	dev->driver_data = data;
@@ -436,5 +436,5 @@
 	/* Enable interrupt globally. */
 	res = interrupt_enable(data->irq);
-	if (EOK != res)
+	if (res != EOK)
 		return res;
 	
@@ -480,5 +480,5 @@
 	uint8_t div_low, div_high;
 	
-	if (50 > baud_rate || 0 != MAX_BAUD_RATE % baud_rate) {
+	if (baud_rate < 50 || MAX_BAUD_RATE % baud_rate != 0) {
 		printf(NAME ": error - somebody tried to set invalid baud rate "
 		    "%d\n", baud_rate);
@@ -534,6 +534,5 @@
  * @param stop_bits	The number of stop bits used (one or two).
  */
-static void
-ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity,
+static void ns8250_port_get_com_props(ioport8_t *port, unsigned int *parity,
     unsigned int *word_length, unsigned int *stop_bits)
 {
@@ -572,6 +571,5 @@
  *			is invalid.
  */
-static int
-ns8250_port_set_com_props(ioport8_t *port, unsigned int parity,
+static int ns8250_port_set_com_props(ioport8_t *port, unsigned int parity,
     unsigned int word_length, unsigned int stop_bits)
 {
@@ -691,6 +689,6 @@
  * @param dev		The serial port device.
  */
-static inline void
-ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid, ipc_call_t *icall)
+static inline void ns8250_interrupt_handler(device_t *dev, ipc_callid_t iid,
+    ipc_call_t *icall)
 {
 	ns8250_read_from_device(dev);
@@ -726,5 +724,5 @@
  * @param dev		The serial port device.
  */
-static int ns8250_add_device(device_t *dev) 
+static int ns8250_add_device(device_t *dev)
 {
 	printf(NAME ": ns8250_add_device %s (handle = %d)\n",
@@ -732,5 +730,5 @@
 	
 	int res = ns8250_dev_initialize(dev);
-	if (EOK != res)
+	if (res != EOK)
 		return res;
 	
@@ -750,5 +748,5 @@
 	
 	/* Register interrupt handler. */
-	if (EOK != ns8250_register_interrupt_handler(dev)) {
+	if (ns8250_register_interrupt_handler(dev) != EOK) {
 		printf(NAME ": failed to register interrupt handler.\n");
 		ns8250_dev_cleanup(dev);
@@ -758,5 +756,5 @@
 	/* Enable interrupt. */
 	res = ns8250_interrupt_enable(dev);
-	if (EOK != res) {
+	if (res != EOK) {
 		printf(NAME ": failed to enable the interrupt. Error code = "
 		    "%d.\n", res);
@@ -859,7 +857,6 @@
  * @param stop_bits	The number of stop bits to be used.
  */
-static int
-ns8250_set_props(device_t *dev, unsigned int baud_rate, unsigned int parity,
-    unsigned int word_length, unsigned int stop_bits)
+static int ns8250_set_props(device_t *dev, unsigned int baud_rate,
+    unsigned int parity, unsigned int word_length, unsigned int stop_bits)
 {
 	printf(NAME ": ns8250_set_props: baud rate %d, parity 0x%x, word "
@@ -874,5 +871,5 @@
 	ns8250_port_interrupts_disable(port);
 	ret = ns8250_port_set_baud_rate(port, baud_rate);
-	if (EOK == ret)
+	if (ret == EOK)
 		ret = ns8250_port_set_com_props(port, parity, word_length, stop_bits);
 	ns8250_port_interrupts_enable(port);
@@ -887,6 +884,6 @@
  * Configure the parameters of the serial communication.
  */
-static void
-ns8250_default_handler(device_t *dev, ipc_callid_t callid, ipc_call_t *call)
+static void ns8250_default_handler(device_t *dev, ipc_callid_t callid,
+    ipc_call_t *call)
 {
 	ipcarg_t method = IPC_GET_METHOD(*call);
Index: uspace/drv/pciintel/pci.c
===================================================================
--- uspace/drv/pciintel/pci.c	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/drv/pciintel/pci.c	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -65,5 +65,5 @@
 	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
 	
-	if (NULL == dev_data)
+	if (dev_data == NULL)
 		return NULL;
 	return &dev_data->hw_resources;
@@ -109,8 +109,9 @@
 	
 	bus_data = (pci_bus_data_t *) malloc(sizeof(pci_bus_data_t));
-	if (NULL != bus_data) {
+	if (bus_data != NULL) {
 		memset(bus_data, 0, sizeof(pci_bus_data_t));
 		fibril_mutex_initialize(&bus_data->conf_mutex);
 	}
+
 	return bus_data;
 }
@@ -123,5 +124,5 @@
 static void pci_conf_read(device_t *dev, int reg, uint8_t *buf, size_t len)
 {
-	assert(NULL != dev->parent);
+	assert(dev->parent != NULL);
 	
 	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
@@ -153,5 +154,5 @@
 static void pci_conf_write(device_t *dev, int reg, uint8_t *buf, size_t len)
 {
-	assert(NULL != dev->parent);
+	assert(dev->parent != NULL);
 	
 	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
@@ -224,5 +225,5 @@
 	
 	match_id = create_match_id();
-	if (NULL != match_id) {
+	if (match_id != NULL) {
 		asprintf(&match_id_str, "pci/ven=%04x&dev=%04x",
 		    dev_data->vendor_id, dev_data->device_id);
@@ -230,5 +231,6 @@
 		match_id->score = 90;
 		add_match_id(&dev->match_ids, match_id);
-	}	
+	}
+
 	/* TODO add more ids (with subsys ids, using class id etc.) */
 }
@@ -242,5 +244,5 @@
 	size_t count = hw_res_list->count;
 	
-	assert(NULL != hw_resources);
+	assert(hw_resources != NULL);
 	assert(count < PCI_MAX_HW_RES);
 	
@@ -275,5 +277,5 @@
 	bool io;
 	/* 64-bit wide address */
-	bool w64;
+	bool addrw64;
 	
 	/* Size of the io or memory range specified by the BAR */
@@ -287,12 +289,12 @@
 	io = (bool) (val & 1);
 	if (io) {
-		w64 = false;
+		addrw64 = false;
 	} else {
 		switch ((val >> 1) & 3) {
 		case 0:
-			w64 = false;
+			addrw64 = false;
 			break;
 		case 2:
-			w64 = true;
+			addrw64 = true;
 			break;
 		default:
@@ -312,5 +314,5 @@
 	range_size = pci_bar_mask_to_size(mask);
 	
-	if (w64) {
+	if (addrw64) {
 		range_addr = ((uint64_t)pci_conf_read_32(dev, addr + 4) << 32) |
 		    (val & 0xfffffff0);
@@ -319,5 +321,5 @@
 	}
 	
-	if (0 != range_addr) {
+	if (range_addr != 0) {
 		printf(NAME ": device %s : ", dev->name);
 		printf("address = %x", range_addr);
@@ -327,5 +329,5 @@
 	pci_add_range(dev, range_addr, range_size, io);
 	
-	if (w64)
+	if (addrw64)
 		return addr + 8;
 	
@@ -354,5 +356,5 @@
 {
 	uint8_t irq = pci_conf_read_8(dev, PCI_BRIDGE_INT_LINE);
-	if (0xff != irq)
+	if (irq != 0xff)
 		pci_add_interrupt(dev, irq);
 }
@@ -415,5 +417,5 @@
 			create_pci_match_ids(dev);
 			
-			if (EOK != child_device_register(dev, parent)) {
+			if (child_device_register(dev, parent) != EOK) {
 				pci_clean_resource_list(dev);
 				clean_match_ids(&dev->match_ids);
@@ -424,10 +426,10 @@
 			
 			if (header_type == PCI_HEADER_TYPE_BRIDGE ||
-			    header_type == PCI_HEADER_TYPE_CARDBUS ) {
+			    header_type == PCI_HEADER_TYPE_CARDBUS) {
 				child_bus = pci_conf_read_8(dev,
 				    PCI_BRIDGE_SEC_BUS_NUM);
 				printf(NAME ": device is pci-to-pci bridge, "
 				    "secondary bus number = %d.\n", bus_num);
-				if(child_bus > bus_num)
+				if (child_bus > bus_num)
 					pci_bus_scan(parent, child_bus);
 			}
@@ -453,5 +455,5 @@
 	
 	pci_bus_data_t *bus_data = create_pci_bus_data();
-	if (NULL == bus_data) {
+	if (bus_data == NULL) {
 		printf(NAME ": pci_add_device allocation failed.\n");
 		return ENOMEM;
@@ -513,4 +515,79 @@
 }
 
+pci_dev_data_t *create_pci_dev_data(void)
+{
+	pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
+	
+	if (res != NULL)
+		memset(res, 0, sizeof(pci_dev_data_t));
+	return res;
+}
+
+void init_pci_dev_data(pci_dev_data_t *dev_data, int bus, int dev, int fn)
+{
+	dev_data->bus = bus;
+	dev_data->dev = dev;
+	dev_data->fn = fn;
+}
+
+void delete_pci_dev_data(pci_dev_data_t *dev_data)
+{
+	if (dev_data != NULL) {
+		clean_hw_resource_list(&dev_data->hw_resources);
+		free(dev_data);
+	}
+}
+
+void create_pci_dev_name(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	char *name = NULL;
+	
+	asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
+	    dev_data->fn);
+	dev->name = name;
+}
+
+bool pci_alloc_resource_list(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
+	
+	dev_data->hw_resources.resources =
+	    (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
+	return dev_data->hw_resources.resources != NULL;
+}
+
+void pci_clean_resource_list(device_t *dev)
+{
+	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
+	
+	if (dev_data->hw_resources.resources != NULL) {
+		free(dev_data->hw_resources.resources);
+		dev_data->hw_resources.resources = NULL;
+	}
+}
+
+/** Read the base address registers (BARs) of the device and adds the addresses
+ * to its hw resource list.
+ *
+ * @param dev the pci device.
+ */
+void pci_read_bars(device_t *dev)
+{
+	/*
+	 * Position of the BAR in the PCI configuration address space of the
+	 * device.
+	 */
+	int addr = PCI_BASE_ADDR_0;
+	
+	while (addr <= PCI_BASE_ADDR_5)
+		addr = pci_read_bar(dev, addr);
+}
+
+size_t pci_bar_mask_to_size(uint32_t mask)
+{
+	return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
+}
+
 int main(int argc, char *argv[])
 {
Index: uspace/drv/pciintel/pci.h
===================================================================
--- uspace/drv/pciintel/pci.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/drv/pciintel/pci.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -69,79 +69,14 @@
 extern void pci_bus_scan(device_t *, int);
 
-static inline pci_dev_data_t *create_pci_dev_data(void)
-{
-	pci_dev_data_t *res = (pci_dev_data_t *) malloc(sizeof(pci_dev_data_t));
-	
-	if (NULL != res)
-		memset(res, 0, sizeof(pci_dev_data_t));
-	return res;
-}
+extern pci_dev_data_t *create_pci_dev_data(void);
+extern void init_pci_dev_data(pci_dev_data_t *, int, int, int);
+extern void delete_pci_dev_data(pci_dev_data_t *);
+extern void create_pci_dev_name(device_t *);
 
-static inline void
-init_pci_dev_data(pci_dev_data_t *d, int bus, int dev, int fn)
-{
-	d->bus = bus;
-	d->dev = dev;
-	d->fn = fn;
-}
+extern bool pci_alloc_resource_list(device_t *);
+extern void pci_clean_resource_list(device_t *);
 
-static inline void delete_pci_dev_data(pci_dev_data_t *d)
-{
-	if (NULL != d) {
-		clean_hw_resource_list(&d->hw_resources);
-		free(d);
-	}
-}
-
-static inline void create_pci_dev_name(device_t *dev)
-{
-	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
-	char *name = NULL;
-	
-	asprintf(&name, "%02x:%02x.%01x", dev_data->bus, dev_data->dev,
-	    dev_data->fn);
-	dev->name = name;
-}
-
-static inline bool pci_alloc_resource_list(device_t *dev)
-{
-	pci_dev_data_t *dev_data = (pci_dev_data_t *)dev->driver_data;
-	
-	dev_data->hw_resources.resources =
-	    (hw_resource_t *) malloc(PCI_MAX_HW_RES * sizeof(hw_resource_t));
-	return dev_data->hw_resources.resources != NULL;
-}
-
-static inline void pci_clean_resource_list(device_t *dev)
-{
-	pci_dev_data_t *dev_data = (pci_dev_data_t *) dev->driver_data;
-	
-	if (NULL != dev_data->hw_resources.resources) {
-		free(dev_data->hw_resources.resources);
-		dev_data->hw_resources.resources = NULL;
-	}
-}
-
-/** Read the base address registers (BARs) of the device and adds the addresses
- * to its hw resource list.
- *
- * @param dev the pci device.
- */
-static inline  void pci_read_bars(device_t *dev)
-{
-	/*
-	 * Position of the BAR in the PCI configuration address space of the
-	 * device.
-	 */
-	int addr = PCI_BASE_ADDR_0;
-	
-	while (addr <= PCI_BASE_ADDR_5)
-		addr = pci_read_bar(dev, addr);
-}
-
-static inline size_t pci_bar_mask_to_size(uint32_t mask)
-{
-	return ((mask & 0xfffffff0) ^ 0xffffffff) + 1;
-}
+extern void pci_read_bars(device_t *);
+extern size_t pci_bar_mask_to_size(uint32_t);
 
 #endif
Index: uspace/lib/c/arch/abs32le/include/fibril.h
===================================================================
--- uspace/lib/c/arch/abs32le/include/fibril.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/arch/abs32le/include/fibril.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -44,4 +44,5 @@
 		(ctx)->pc = (uintptr_t) (_pc); \
 		(ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
+		(ctx)->fp = 0; \
 		(ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \
 	} while (0)
@@ -53,7 +54,14 @@
 typedef struct {
 	uintptr_t sp;
+	uintptr_t fp;
 	uintptr_t pc;
 	uintptr_t tls;
 } context_t;
+
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	/* On real hardware, this function returns the frame pointer. */
+	return ctx->fp;
+}
 
 #endif
Index: uspace/lib/c/arch/amd64/include/fibril.h
===================================================================
--- uspace/lib/c/arch/amd64/include/fibril.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/arch/amd64/include/fibril.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -56,17 +56,22 @@
  */
 typedef struct {
-    uint64_t sp;
-    uint64_t pc;
-    
-    uint64_t rbx;
-    uint64_t rbp;
+	uint64_t sp;
+	uint64_t pc;
 
-    uint64_t r12;
-    uint64_t r13;
-    uint64_t r14;
-    uint64_t r15;
+	uint64_t rbx;
+	uint64_t rbp;
 
-    uint64_t tls;
+	uint64_t r12;
+	uint64_t r13;
+	uint64_t r14;
+	uint64_t r15;
+
+	uint64_t tls;
 } context_t;
+
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->rbp;
+}
 
 #endif
Index: uspace/lib/c/arch/arm32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/arm32/include/fibril.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/arch/arm32/include/fibril.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -86,4 +86,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->fp;
+}
+
 
 #endif
Index: uspace/lib/c/arch/ia32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/ia32/include/fibril.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/arch/ia32/include/fibril.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -67,4 +67,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->ebp;
+}
+
 #endif
 
Index: uspace/lib/c/arch/ia64/include/fibril.h
===================================================================
--- uspace/lib/c/arch/ia64/include/fibril.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/arch/ia64/include/fibril.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -130,4 +130,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return 0;	/* FIXME */
+}
+
 #endif
 
Index: uspace/lib/c/arch/mips32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/mips32/include/fibril.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/arch/mips32/include/fibril.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -85,4 +85,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->sp;
+}
+
 #endif
 
Index: uspace/lib/c/arch/ppc32/include/fibril.h
===================================================================
--- uspace/lib/c/arch/ppc32/include/fibril.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/arch/ppc32/include/fibril.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -78,4 +78,9 @@
 } __attribute__ ((packed)) context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->sp;
+}
+
 #endif
 
Index: uspace/lib/c/arch/sparc64/include/fibril.h
===================================================================
--- uspace/lib/c/arch/sparc64/include/fibril.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/arch/sparc64/include/fibril.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -77,4 +77,9 @@
 } context_t;
 
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	return ctx->sp + STACK_BIAS;
+}
+
 #endif
 
Index: uspace/lib/c/generic/fibril.c
===================================================================
--- uspace/lib/c/generic/fibril.c	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/generic/fibril.c	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -275,4 +275,6 @@
 	fibril->func = func;
 	fibril->arg = arg;
+
+	fibril->waits_for = NULL;
 	
 	context_save(&fibril->ctx);
Index: uspace/lib/c/generic/fibril_synch.c
===================================================================
--- uspace/lib/c/generic/fibril_synch.c	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/generic/fibril_synch.c	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -42,4 +42,6 @@
 #include <errno.h>
 #include <assert.h>
+#include <stacktrace.h>
+#include <stdlib.h>
 
 static void optimize_execution_power(void)
@@ -56,6 +58,42 @@
 }
 
+static bool check_for_deadlock(fibril_owner_info_t *oi)
+{
+	while (oi && oi->owned_by) {
+		if (oi->owned_by == (fibril_t *) fibril_get_id())
+			return true;
+		oi = oi->owned_by->waits_for;
+	}
+
+	return false;
+}
+
+static void print_deadlock(fibril_owner_info_t *oi)
+{
+	fibril_t *f = (fibril_t *) fibril_get_id();
+
+	printf("Deadlock detected.\n");
+	stacktrace_print();
+
+	printf("Fibril %p waits for primitive %p.\n", f, oi);
+
+	while (oi && oi->owned_by) {
+		printf("Primitive %p is owned by fibril %p.\n",
+		    oi, oi->owned_by);
+		if (oi->owned_by == f)
+			break;
+		stacktrace_print_fp_pc(context_get_fp(&oi->owned_by->ctx),
+		    oi->owned_by->ctx.pc);
+		printf("Fibril %p waits for primitive %p.\n",
+		     oi->owned_by, oi->owned_by->waits_for);
+		oi = oi->owned_by->waits_for;
+	}
+
+	abort();
+}
+
 void fibril_mutex_initialize(fibril_mutex_t *fm)
 {
+	fm->oi.owned_by = NULL;
 	fm->counter = 1;
 	list_initialize(&fm->waiters);
@@ -64,4 +102,6 @@
 void fibril_mutex_lock(fibril_mutex_t *fm)
 {
+	fibril_t *f = (fibril_t *) fibril_get_id();
+
 	futex_down(&async_futex);
 	if (fm->counter-- <= 0) {
@@ -73,6 +113,12 @@
 		link_initialize(&wdata.wu_event.link);
 		list_append(&wdata.wu_event.link, &fm->waiters);
+
+		if (check_for_deadlock(&fm->oi))
+			print_deadlock(&fm->oi);
+		f->waits_for = &fm->oi;
+
 		fibril_switch(FIBRIL_TO_MANAGER);
 	} else {
+		fm->oi.owned_by = f;
 		futex_up(&async_futex);
 	}
@@ -86,4 +132,5 @@
 	if (fm->counter > 0) {
 		fm->counter--;
+		fm->oi.owned_by = (fibril_t *) fibril_get_id();
 		locked = true;
 	}
@@ -99,4 +146,5 @@
 		link_t *tmp;
 		awaiter_t *wdp;
+		fibril_t *f;
 	
 		assert(!list_empty(&fm->waiters));
@@ -105,7 +153,14 @@
 		wdp->active = true;
 		wdp->wu_event.inlist = false;
+
+		f = (fibril_t *) wdp->fid;
+		fm->oi.owned_by = f;
+		f->waits_for = NULL;
+
 		list_remove(&wdp->wu_event.link);
 		fibril_add_ready(wdp->fid);
 		optimize_execution_power();
+	} else {
+		fm->oi.owned_by = NULL;
 	}
 }
@@ -120,4 +175,5 @@
 void fibril_rwlock_initialize(fibril_rwlock_t *frw)
 {
+	frw->oi.owned_by = NULL;
 	frw->writers = 0;
 	frw->readers = 0;
Index: uspace/lib/c/include/fibril.h
===================================================================
--- uspace/lib/c/include/fibril.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/include/fibril.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -48,4 +48,10 @@
 #define FIBRIL_WRITER      2
 
+struct fibril;
+
+typedef struct {
+	struct fibril *owned_by;
+} fibril_owner_info_t;
+
 typedef enum {
 	FIBRIL_PREEMPT,
@@ -68,4 +74,6 @@
 	int retval;
 	int flags;
+
+	fibril_owner_info_t *waits_for;
 } fibril_t;
 
Index: uspace/lib/c/include/fibril_synch.h
===================================================================
--- uspace/lib/c/include/fibril_synch.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/lib/c/include/fibril_synch.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -43,4 +43,5 @@
 
 typedef struct {
+	fibril_owner_info_t oi;		/* Keep this the first thing. */
 	int counter;
 	link_t waiters;
@@ -49,4 +50,7 @@
 #define FIBRIL_MUTEX_INITIALIZER(name) \
 	{ \
+		.oi = { \
+			.owned_by = NULL \
+		}, \
 		.counter = 1, \
 		.waiters = { \
@@ -60,4 +64,5 @@
 
 typedef struct {
+	fibril_owner_info_t oi;	/* Keep this the first thing. */
 	unsigned writers;
 	unsigned readers;
@@ -67,4 +72,7 @@
 #define FIBRIL_RWLOCK_INITIALIZER(name) \
 	{ \
+		.oi = { \
+			.owned_by = NULL \
+		}, \
 		.readers = 0, \
 		.writers = 0, \
Index: uspace/lib/packet/include/netdb.h
===================================================================
--- uspace/lib/packet/include/netdb.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
+++ uspace/lib/packet/include/netdb.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * 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 netdb
+ *  @{
+ */
+
+/** @file
+ *  Structures and interfaces according to the BSD netdb.h file.
+ */
+
+#ifndef __NET_NETDB_H__
+#define __NET_NETDB_H__
+
+#include <sys/types.h>
+
+/** Structure returned by network data base library.
+ *  All addresses are supplied in host order, and returned in network order (suitable for use in system calls).
+ */
+struct	hostent {
+	/** Official host name.
+	 */
+	char * h_name;
+	/** Alias list.
+	 */
+	char **	h_aliases;
+	/** Host address type.
+	 */
+	int h_addrtype;
+	/** Address length.
+	 */
+	int h_length;
+	/** List of addresses from name server.
+	 */
+	char **	h_addr_list;
+	/** Address, for backward compatiblity.
+	 */
+#define	h_addr	h_addr_list[0]
+};
+
+/** @name Host entry address types definitions.
+ */
+/*@{*/
+
+/** Authoritative Answer Host not found address type.
+ */
+#define	HOST_NOT_FOUND	1
+
+/** Non-Authoritive Host not found, or SERVERFAIL address type.
+ */
+#define	TRY_AGAIN	2
+
+/** Non recoverable errors, FORMERR, REFUSED, NOTIMP address type.
+ */
+#define	NO_RECOVERY	3
+
+/** Valid name, no data record of requested type address type.
+ */
+#define	NO_DATA		4
+
+/** No address, look for MX record address type.
+ */
+#define	NO_ADDRESS	NO_DATA
+
+/*@}*/
+
+/** Returns host entry by the host address.
+ *  @param[in] address The host address.
+ *  @param[in] len The address length.
+ *  @param[in] type The address type.
+ *  @returns Host entry information.
+ */
+//struct hostent *	gethostbyaddr(const void * address, int len, int type);
+
+/** Returns host entry by the host name.
+ *  @param[in] name The host name.
+ *  @returns Host entry information.
+ */
+//struct hostent *	gethostbyname(const char * name);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/packet/include/tcp_codes.h
===================================================================
--- uspace/lib/packet/include/tcp_codes.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
+++ uspace/lib/packet/include/tcp_codes.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * 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 tcp
+ *  @{
+ */
+
+/** @file
+ *  TCP options definitions.
+ */
+
+#ifndef __NET_TCP_CODES_H__
+#define __NET_TCP_CODES_H__
+
+/** End of list TCP option.
+ */
+#define TCPOPT_END_OF_LIST				0x0
+
+/** No operation TCP option.
+ */
+#define TCPOPT_NO_OPERATION				0x1
+
+/** Maximum segment size TCP option.
+ */
+#define TCPOPT_MAX_SEGMENT_SIZE			0x2
+
+/** Maximum segment size TCP option length.
+ */
+#define TCPOPT_MAX_SEGMENT_SIZE_LENGTH	4
+
+/** Window scale TCP option.
+ */
+#define TCPOPT_WINDOW_SCALE				0x3
+
+/** Window scale TCP option length.
+ */
+#define TCPOPT_WINDOW_SCALE_LENGTH		3
+
+/** Selective acknowledgement permitted TCP option.
+ */
+#define TCPOPT_SACK_PERMITTED			0x4
+
+/** Selective acknowledgement permitted TCP option length.
+ */
+#define TCPOPT_SACK_PERMITTED_LENGTH	2
+
+/** Selective acknowledgement TCP option.
+ *  Has variable length.
+ */
+#define TCPOPT_SACK						0x5
+
+/** Timestamp TCP option.
+ */
+#define TCPOPT_TIMESTAMP				0x8
+
+/** Timestamp TCP option length.
+ */
+#define TCPOPT_TIMESTAMP_LENGTH			10
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/devman/devman.c
===================================================================
--- uspace/srv/devman/devman.c	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/srv/devman/devman.c	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -76,4 +76,18 @@
 	.remove_callback = devices_remove_callback
 };
+
+/**
+ * Initialize the list of device driver's.
+ *
+ * @param drv_list the list of device driver's.
+ *
+ */
+void init_driver_list(driver_list_t *drv_list)
+{
+	assert(drv_list != NULL);
+	
+	list_initialize(&drv_list->drivers);
+	fibril_mutex_initialize(&drv_list->drivers_mutex);
+}
 
 /** Allocate and initialize a new driver structure.
@@ -548,4 +562,45 @@
 }
 
+/** Initialize device driver structure.
+ *
+ * @param drv		The device driver structure.
+ */
+void init_driver(driver_t *drv)
+{
+	assert(drv != NULL);
+
+	memset(drv, 0, sizeof(driver_t));
+	list_initialize(&drv->match_ids.ids);
+	list_initialize(&drv->devices);
+	fibril_mutex_initialize(&drv->driver_mutex);
+}
+
+/** Device driver structure clean-up.
+ *
+ * @param drv		The device driver structure.
+ */
+void clean_driver(driver_t *drv)
+{
+	assert(drv != NULL);
+
+	free_not_null(drv->name);
+	free_not_null(drv->binary_path);
+
+	clean_match_ids(&drv->match_ids);
+
+	init_driver(drv);
+}
+
+/** Delete device driver structure.
+ *
+ * @param drv		The device driver structure.
+ */
+void delete_driver(driver_t *drv)
+{
+	assert(drv != NULL);
+	
+	clean_driver(drv);
+	free(drv);
+}
 
 /** Create devmap path and name for the device. */
@@ -685,4 +740,73 @@
 }
 
+/* Device nodes */
+
+/** Create a new device node.
+ *
+ * @return		A device node structure.
+ */
+node_t *create_dev_node(void)
+{
+	node_t *res = malloc(sizeof(node_t));
+	
+	if (res != NULL) {
+		memset(res, 0, sizeof(node_t));
+		list_initialize(&res->children);
+		list_initialize(&res->match_ids.ids);
+		list_initialize(&res->classes);
+	}
+	
+	return res;
+}
+
+/** Delete a device node.
+ *
+ * @param node		The device node structure.
+ */
+void delete_dev_node(node_t *node)
+{
+	assert(list_empty(&node->children));
+	assert(node->parent == NULL);
+	assert(node->drv == NULL);
+	
+	clean_match_ids(&node->match_ids);
+	free_not_null(node->name);
+	free_not_null(node->pathname);
+	free(node);
+}
+
+/** Find the device node structure of the device witch has the specified handle.
+ *
+ * Device tree's rwlock should be held at least for reading.
+ *
+ * @param tree		The device tree where we look for the device node.
+ * @param handle	The handle of the device.
+ * @return		The device node.
+ */
+node_t *find_dev_node_no_lock(dev_tree_t *tree, device_handle_t handle)
+{
+	unsigned long key = handle;
+	link_t *link = hash_table_find(&tree->devman_devices, &key);
+	return hash_table_get_instance(link, node_t, devman_link);
+}
+
+/** Find the device node structure of the device witch has the specified handle.
+ *
+ * @param tree		The device tree where we look for the device node.
+ * @param handle	The handle of the device.
+ * @return		The device node.
+ */
+node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
+{
+	node_t *node = NULL;
+	
+	fibril_rwlock_read_lock(&tree->rwlock);
+	node = find_dev_node_no_lock(tree, handle);
+	fibril_rwlock_read_unlock(&tree->rwlock);
+	
+	return node;
+}
+
+
 /** Create and set device's full path in device tree.
  *
@@ -825,4 +949,51 @@
 	return NULL;
 }
+
+/* Device classes */
+
+/** Create device class.
+ *
+ * @return	Device class.
+ */
+dev_class_t *create_dev_class(void)
+{
+	dev_class_t *cl;
+	
+	cl = (dev_class_t *) malloc(sizeof(dev_class_t));
+	if (cl != NULL) {
+		memset(cl, 0, sizeof(dev_class_t));
+		list_initialize(&cl->devices);
+		fibril_mutex_initialize(&cl->mutex);
+	}
+	
+	return cl;
+}
+
+/** Create device class info.
+ *
+ * @return		Device class info.
+ */
+dev_class_info_t *create_dev_class_info(void)
+{
+	dev_class_info_t *info;
+	
+	info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
+	if (info != NULL)
+		memset(info, 0, sizeof(dev_class_info_t));
+	
+	return info;
+}
+
+size_t get_new_class_dev_idx(dev_class_t *cl)
+{
+	size_t dev_idx;
+	
+	fibril_mutex_lock(&cl->mutex);
+	dev_idx = ++cl->curr_dev_idx;
+	fibril_mutex_unlock(&cl->mutex);
+	
+	return dev_idx;
+}
+
 
 /** Create unique device name within the class.
@@ -921,4 +1092,9 @@
 }
 
+void add_dev_class_no_lock(class_list_t *class_list, dev_class_t *cl)
+{
+	list_append(&cl->link, &class_list->classes);
+}
+
 void init_class_list(class_list_t *class_list)
 {
@@ -930,5 +1106,5 @@
 
 
-/* devmap devices */
+/* Devmap devices */
 
 node_t *find_devmap_tree_device(dev_tree_t *tree, dev_handle_t devmap_handle)
@@ -967,4 +1143,21 @@
 }
 
+void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
+{
+	unsigned long key = (unsigned long) cli->devmap_handle;
+	
+	fibril_rwlock_write_lock(&class_list->rwlock);
+	hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
+	fibril_rwlock_write_unlock(&class_list->rwlock);
+}
+
+void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
+{
+	unsigned long key = (unsigned long) node->devmap_handle;
+	fibril_rwlock_write_lock(&tree->rwlock);
+	hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
+	fibril_rwlock_write_unlock(&tree->rwlock);
+}
+
 /** @}
  */
Index: uspace/srv/devman/devman.h
===================================================================
--- uspace/srv/devman/devman.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/srv/devman/devman.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -283,18 +283,5 @@
 /* Drivers */
 
-/**
- * Initialize the list of device driver's.
- *
- * @param drv_list the list of device driver's.
- *
- */
-static inline void init_driver_list(driver_list_t *drv_list)
-{
-	assert(drv_list != NULL);
-	
-	list_initialize(&drv_list->drivers);
-	fibril_mutex_initialize(&drv_list->drivers_mutex);
-}
-
+extern void init_driver_list(driver_list_t *);
 extern driver_t *create_driver(void);
 extern bool get_driver_info(const char *, const char *, driver_t *);
@@ -311,121 +298,19 @@
 extern driver_t *find_driver(driver_list_t *, const char *);
 extern void set_driver_phone(driver_t *, ipcarg_t);
-void initialize_running_driver(driver_t *, dev_tree_t *);
-
-/** Initialize device driver structure.
- *
- * @param drv		The device driver structure.
- */
-static inline void init_driver(driver_t *drv)
-{
-	assert(drv != NULL);
-
-	memset(drv, 0, sizeof(driver_t));
-	list_initialize(&drv->match_ids.ids);
-	list_initialize(&drv->devices);
-	fibril_mutex_initialize(&drv->driver_mutex);
-}
-
-/** Device driver structure clean-up.
- *
- * @param drv		The device driver structure.
- */
-static inline void clean_driver(driver_t *drv)
-{
-	assert(drv != NULL);
-
-	free_not_null(drv->name);
-	free_not_null(drv->binary_path);
-
-	clean_match_ids(&drv->match_ids);
-
-	init_driver(drv);
-}
-
-/** Delete device driver structure.
- *
- * @param drv		The device driver structure.
- */
-static inline void delete_driver(driver_t *drv)
-{
-	assert(drv != NULL);
-	
-	clean_driver(drv);
-	free(drv);
-}
-
+extern void initialize_running_driver(driver_t *, dev_tree_t *);
+
+extern void init_driver(driver_t *);
+extern void clean_driver(driver_t *);
+extern void delete_driver(driver_t *);
 
 /* Device nodes */
 
-/** Create a new device node.
- *
- * @return		A device node structure.
- */
-static inline node_t *create_dev_node(void)
-{
-	node_t *res = malloc(sizeof(node_t));
-	
-	if (res != NULL) {
-		memset(res, 0, sizeof(node_t));
-		list_initialize(&res->children);
-		list_initialize(&res->match_ids.ids);
-		list_initialize(&res->classes);
-	}
-	
-	return res;
-}
-
-/** Delete a device node.
- *
- * @param node		The device node structure.
- */
-static inline void delete_dev_node(node_t *node)
-{
-	assert(list_empty(&node->children));
-	assert(node->parent == NULL);
-	assert(node->drv == NULL);
-	
-	clean_match_ids(&node->match_ids);
-	free_not_null(node->name);
-	free_not_null(node->pathname);
-	free(node);
-}
-
-/** Find the device node structure of the device witch has the specified handle.
- *
- * Device tree's rwlock should be held at least for reading.
- *
- * @param tree		The device tree where we look for the device node.
- * @param handle	The handle of the device.
- * @return		The device node.
- */
-static inline node_t *find_dev_node_no_lock(dev_tree_t *tree,
-    device_handle_t handle)
-{
-	unsigned long key = handle;
-	link_t *link = hash_table_find(&tree->devman_devices, &key);
-	return hash_table_get_instance(link, node_t, devman_link);
-}
-
-/** Find the device node structure of the device witch has the specified handle.
- *
- * @param tree		The device tree where we look for the device node.
- * @param handle	The handle of the device.
- * @return		The device node.
- */
-static inline node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle)
-{
-	node_t *node = NULL;
-	
-	fibril_rwlock_read_lock(&tree->rwlock);
-	node = find_dev_node_no_lock(tree, handle);
-	fibril_rwlock_read_unlock(&tree->rwlock);
-	
-	return node;
-}
-
+extern node_t *create_dev_node(void);
+extern void delete_dev_node(node_t *node);
+extern node_t *find_dev_node_no_lock(dev_tree_t *tree,
+    device_handle_t handle);
+extern node_t *find_dev_node(dev_tree_t *tree, device_handle_t handle);
 extern node_t *find_dev_node_by_path(dev_tree_t *, char *);
 extern node_t *find_node_child(node_t *, const char *);
-
 
 /* Device tree */
@@ -435,51 +320,9 @@
 extern bool insert_dev_node(dev_tree_t *, node_t *, char *, node_t *);
 
-
 /* Device classes */
 
-/** Create device class.
- *
- * @return	Device class.
- */
-static inline dev_class_t *create_dev_class(void)
-{
-	dev_class_t *cl;
-	
-	cl = (dev_class_t *) malloc(sizeof(dev_class_t));
-	if (cl != NULL) {
-		memset(cl, 0, sizeof(dev_class_t));
-		list_initialize(&cl->devices);
-		fibril_mutex_initialize(&cl->mutex);
-	}
-	
-	return cl;
-}
-
-/** Create device class info.
- *
- * @return		Device class info.
- */
-static inline dev_class_info_t *create_dev_class_info(void)
-{
-	dev_class_info_t *info;
-	
-	info = (dev_class_info_t *) malloc(sizeof(dev_class_info_t));
-	if (info != NULL)
-		memset(info, 0, sizeof(dev_class_info_t));
-	
-	return info;
-}
-
-static inline size_t get_new_class_dev_idx(dev_class_t *cl)
-{
-	size_t dev_idx;
-	
-	fibril_mutex_lock(&cl->mutex);
-	dev_idx = ++cl->curr_dev_idx;
-	fibril_mutex_unlock(&cl->mutex);
-	
-	return dev_idx;
-}
-
+extern dev_class_t *create_dev_class(void);
+extern dev_class_info_t *create_dev_class_info(void);
+extern size_t get_new_class_dev_idx(dev_class_t *);
 extern char *create_dev_name_for_class(dev_class_t *, const char *);
 extern dev_class_info_t *add_device_to_class(node_t *, dev_class_t *,
@@ -490,11 +333,5 @@
 extern dev_class_t *get_dev_class(class_list_t *, char *);
 extern dev_class_t *find_dev_class_no_lock(class_list_t *, const char *);
-
-static inline void add_dev_class_no_lock(class_list_t *class_list,
-    dev_class_t *cl)
-{
-	list_append(&cl->link, &class_list->classes);
-}
-
+extern void add_dev_class_no_lock(class_list_t *, dev_class_t *);
 
 /* Devmap devices */
@@ -503,21 +340,6 @@
 extern node_t *find_devmap_class_device(class_list_t *, dev_handle_t);
 
-static inline void class_add_devmap_device(class_list_t *class_list,
-    dev_class_info_t *cli)
-{
-	unsigned long key = (unsigned long) cli->devmap_handle;
-	
-	fibril_rwlock_write_lock(&class_list->rwlock);
-	hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
-	fibril_rwlock_write_unlock(&class_list->rwlock);
-}
-
-static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
-{
-	unsigned long key = (unsigned long) node->devmap_handle;
-	fibril_rwlock_write_lock(&tree->rwlock);
-	hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
-	fibril_rwlock_write_unlock(&tree->rwlock);
-}
+extern void class_add_devmap_device(class_list_t *, dev_class_info_t *);
+extern void tree_add_devmap_device(dev_tree_t *, node_t *);
 
 #endif
Index: uspace/srv/devman/main.c
===================================================================
--- uspace/srv/devman/main.c	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/srv/devman/main.c	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -66,10 +66,11 @@
 static driver_t *devman_driver_register(void)
 {
+	ipc_call_t icall;
+	ipc_callid_t iid;
+	driver_t *driver = NULL;
+
 	printf(NAME ": devman_driver_register \n");
 	
-	ipc_call_t icall;
-	ipc_callid_t iid = async_get_call(&icall);
-	driver_t *driver = NULL;
-	
+	iid = async_get_call(&icall);
 	if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) {
 		ipc_answer_0(iid, EREFUSED);
@@ -85,4 +86,5 @@
 		return NULL;
 	}
+
 	printf(NAME ": the %s driver is trying to register by the service.\n",
 	    drv_name);
@@ -91,5 +93,5 @@
 	driver = find_driver(&drivers_list, drv_name);
 	
-	if (NULL == driver) {
+	if (driver == NULL) {
 		printf(NAME ": no driver named %s was found.\n", drv_name);
 		free(drv_name);
@@ -146,5 +148,5 @@
 	}
 	
-	if (NULL == match_id) {
+	if (match_id == NULL) {
 		printf(NAME ": ERROR: devman_receive_match_id - failed to "
 		    "allocate match id.\n");
@@ -160,5 +162,5 @@
 	rc = async_data_write_accept((void **) &match_id_str, true, 0, 0, 0, 0);
 	match_id->id = match_id_str;
-	if (EOK != rc) {
+	if (rc != EOK) {
 		delete_match_id(match_id);
 		printf(NAME ": devman_receive_match_id - failed to receive "
@@ -181,6 +183,6 @@
  * @return		Zero on success, negative error code otherwise.
  */
-static int
-devman_receive_match_ids(ipcarg_t match_count, match_id_list_t *match_ids)
+static int devman_receive_match_ids(ipcarg_t match_count,
+    match_id_list_t *match_ids)
 {
 	int ret = EOK;
@@ -205,15 +207,15 @@
 	
 	fibril_rwlock_write_lock(&tree->rwlock);
-	node_t *parent =  find_dev_node_no_lock(&device_tree, parent_handle);
-	
-	if (NULL == parent) {
+	node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle);
+	
+	if (parent == NULL) {
 		fibril_rwlock_write_unlock(&tree->rwlock);
 		ipc_answer_0(callid, ENOENT);
 		return;
-	}	
+	}
 	
 	char *dev_name = NULL;
 	int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0);
-	if (EOK != rc) {
+	if (rc != EOK) {
 		fibril_rwlock_write_unlock(&tree->rwlock);
 		ipc_answer_0(callid, rc);
@@ -227,5 +229,6 @@
 		ipc_answer_0(callid, ENOMEM);
 		return;
-	}	
+	}
+
 	fibril_rwlock_write_unlock(&tree->rwlock);
 	
@@ -245,7 +248,8 @@
 	/* Create devmap path and name for the device. */
 	char *devmap_pathname = NULL;
+
 	asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE,
 	    cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
-	if (NULL == devmap_pathname)
+	if (devmap_pathname == NULL)
 		return;
 	
@@ -279,5 +283,5 @@
 	
 	node_t *dev = find_dev_node(&device_tree, handle);
-	if (NULL == dev) {
+	if (dev == NULL) {
 		ipc_answer_0(callid, ENOENT);
 		return;
@@ -318,5 +322,5 @@
 	
 	driver_t *driver = devman_driver_register();
-	if (NULL == driver)
+	if (driver == NULL)
 		return;
 	
@@ -373,5 +377,5 @@
 	free(pathname);
 
-	if (NULL == dev) {
+	if (dev == NULL) {
 		ipc_answer_0(iid, ENOENT);
 		return;
@@ -404,14 +408,14 @@
 				ipc_answer_0(callid, ENOENT);
 		}
-	}	
-}
-
-static void
-devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent)
+	}
+}
+
+static void devman_forward(ipc_callid_t iid, ipc_call_t *icall,
+    bool drv_to_parent)
 {
 	device_handle_t handle = IPC_GET_ARG2(*icall);
 	
 	node_t *dev = find_dev_node(&device_tree, handle);
-	if (NULL == dev) {
+	if (dev == NULL) {
 		printf(NAME ": devman_forward error - no device with handle %x "
 		    "was found.\n", handle);
@@ -423,12 +427,12 @@
 	
 	if (drv_to_parent) {
-		if (NULL != dev->parent)
+		if (dev->parent != NULL)
 			driver = dev->parent->drv;
-	} else if (DEVICE_USABLE == dev->state) {
+	} else if (dev->state == DEVICE_USABLE) {
 		driver = dev->drv;
-		assert(NULL != driver);
-	}
-	
-	if (NULL == driver) {
+		assert(driver != NULL);
+	}
+	
+	if (driver == NULL) {
 		printf(NAME ": devman_forward error - the device is not in "
 		    "usable state.\n", handle);
@@ -450,4 +454,5 @@
 		return;
 	}
+
 	printf(NAME ": devman_forward: forward connection to device %s to "
 	    "driver %s.\n", dev->pathname, driver->name);
@@ -460,15 +465,16 @@
 {
 	dev_handle_t devmap_handle = IPC_GET_METHOD(*icall);
-	
-	node_t *dev = find_devmap_tree_device(&device_tree, devmap_handle);
-	if (NULL == dev)
+	node_t *dev;
+
+	dev = find_devmap_tree_device(&device_tree, devmap_handle);
+	if (dev == NULL)
 		dev = find_devmap_class_device(&class_list, devmap_handle);
 	
-	if (NULL == dev || NULL == dev->drv) {
+	if (dev == NULL || dev->drv == NULL) {
 		ipc_answer_0(iid, ENOENT);
 		return;
 	}
 	
-	if (DEVICE_USABLE != dev->state || dev->drv->phone <= 0) {
+	if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
 		ipc_answer_0(iid, EINVAL);
 		return;
@@ -493,5 +499,5 @@
 	 * passes device handle to the driver as an ipc method.)
 	 */
-	if (IPC_M_CONNECT_ME_TO != IPC_GET_METHOD(*icall))
+	if (IPC_GET_METHOD(*icall) != IPC_M_CONNECT_ME_TO)
 		devman_connection_devmapper(iid, icall);
 
@@ -531,9 +537,10 @@
 	/* Initialize list of available drivers. */
 	init_driver_list(&drivers_list);
-	if (0 == lookup_available_drivers(&drivers_list,
-	    DRIVER_DEFAULT_STORE)) {
+	if (lookup_available_drivers(&drivers_list,
+	    DRIVER_DEFAULT_STORE) == 0) {
 		printf(NAME " no drivers found.");
 		return false;
 	}
+
 	printf(NAME ": devman_init  - list of drivers has been initialized.\n");
 
Index: uspace/srv/devman/match.c
===================================================================
--- uspace/srv/devman/match.c	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/srv/devman/match.c	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -55,5 +55,5 @@
 		match_id_t *tmp_ma_id;
 	
-		if (0 == str_cmp(drv_id->id, dev_id->id)) {
+		if (str_cmp(drv_id->id, dev_id->id) == 0) {
 		 	/*
 		 	 * We found a match.
@@ -67,5 +67,5 @@
 		 * list of match ids.
 		 */
-		if (drv_head != drv_link->next) {
+		if (drv_link->next != drv_head) {
 			tmp_ma_id = list_get_instance(drv_link->next,
 			    match_id_t, link);
@@ -79,5 +79,5 @@
 		 * list of match ids.
 		 */
-		if (dev_head != dev_link->next) {
+		if (dev_link->next != dev_head) {
 			tmp_ma_id = list_get_instance(dev_link->next,
 			    match_id_t, link);
@@ -99,5 +99,5 @@
 		}
 		
-	} while (drv_head != drv_link->next && dev_head != dev_link->next);
+	} while (drv_link->next != drv_head && dev_link->next != dev_head);
 	
 	return 0;
Index: uspace/srv/devman/util.c
===================================================================
--- uspace/srv/devman/util.c	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/srv/devman/util.c	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -61,9 +61,54 @@
 char *get_path_elem_end(char *path)
 {
-	while (0 != *path && '/' != *path)
+	while (*path != '\0' && *path != '/')
 		path++;
 	return path;
 }
 
+bool skip_spaces(char **buf)
+{
+	while (isspace(**buf))
+		(*buf)++;
+	return *buf != 0;
+}
+
+size_t get_nonspace_len(const char *str)
+{
+	size_t len = 0;
+	
+	while(*str != '\0' && !isspace(*str)) {
+		len++;
+		str++;
+	}
+
+	return len;
+}
+
+void free_not_null(const void *ptr)
+{
+	if (ptr != NULL)
+		free(ptr);
+}
+
+char *clone_string(const char *s)
+{
+	size_t size = str_size(s) + 1;
+	char *str;
+	
+	str = (char *) malloc(size);
+	if (str != NULL)
+		str_cpy(str, size, s);
+	return str;
+}
+
+void replace_char(char *str, char orig, char repl)
+{
+	while (*str) {
+		if (*str == orig)
+			*str = repl;
+		str++;
+	}
+}
+
 /** @}
  */
Index: uspace/srv/devman/util.h
===================================================================
--- uspace/srv/devman/util.h	(revision fd8e8e1bdc24e6988dc181ca0cab34d17aac6da7)
+++ uspace/srv/devman/util.h	(revision 069015f248a0928142a639b1dfb37fb0e2195761)
@@ -41,47 +41,9 @@
 extern char *get_path_elem_end(char *);
 
-static inline bool skip_spaces(char **buf)
-{
-	while (isspace(**buf))
-		(*buf)++;
-	return *buf != 0;
-}
-
-static inline size_t get_nonspace_len(const char *str)
-{
-	size_t len = 0;
-	
-	while(*str != 0 && !isspace(*str)) {
-		len++;
-		str++;
-	}
-	return len;
-}
-
-static inline void free_not_null(const void *ptr)
-{
-	if (NULL != ptr)
-		free(ptr);
-}
-
-static inline char *clone_string(const char *s)
-{
-	size_t size = str_size(s) + 1;
-	char *str;
-	
-	str = (char *) malloc(size);
-	if (NULL != str)
-		str_cpy(str, size, s);
-	return str;
-}
-
-static inline void replace_char(char *str, char orig, char repl)
-{
-	while (*str) {
-		if (orig == *str)
-			*str = repl;
-		str++;
-	}
-}
+extern bool skip_spaces(char **);
+extern size_t get_nonspace_len(const char *);
+extern void free_not_null(const void *);
+extern char *clone_string(const char *);
+extern void replace_char(char *, char, char);
 
 #endif
