Index: uspace/srv/bd/rd/rd.c
===================================================================
--- uspace/srv/bd/rd/rd.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/bd/rd/rd.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -55,6 +55,7 @@
 #include <ipc/bd.h>
 #include <macros.h>
-
-#define NAME "rd"
+#include <inttypes.h>
+
+#define NAME  "rd"
 
 /** Pointer to the ramdisk's image */
@@ -208,39 +209,42 @@
 static bool rd_init(void)
 {
-	int ret = sysinfo_get_value("rd.size", &rd_size);
-	if ((ret != EOK) || (rd_size == 0)) {
+	sysarg_t size;
+	int ret = sysinfo_get_value("rd.size", &size);
+	if ((ret != EOK) || (size == 0)) {
 		printf("%s: No RAM disk found\n", NAME);
 		return false;
 	}
 	
-	sysarg_t rd_ph_addr;
-	ret = sysinfo_get_value("rd.address.physical", &rd_ph_addr);
-	if ((ret != EOK) || (rd_ph_addr == 0)) {
+	sysarg_t addr_phys;
+	ret = sysinfo_get_value("rd.address.physical", &addr_phys);
+	if ((ret != EOK) || (addr_phys == 0)) {
 		printf("%s: Invalid RAM disk physical address\n", NAME);
 		return false;
 	}
 	
+	rd_size = ALIGN_UP(size, block_size);
 	rd_addr = as_get_mappable_page(rd_size);
 	
-	int flags = AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
-	int retval = physmem_map((void *) rd_ph_addr, rd_addr,
+	unsigned int flags =
+	    AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE;
+	ret = physmem_map((void *) addr_phys, rd_addr,
 	    ALIGN_UP(rd_size, PAGE_SIZE) >> PAGE_WIDTH, flags);
-	
-	if (retval < 0) {
+	if (ret < 0) {
 		printf("%s: Error mapping RAM disk\n", NAME);
 		return false;
 	}
 	
-	printf("%s: Found RAM disk at %p, %zu bytes\n", NAME,
-	    (void *) rd_ph_addr, rd_size);
-	
-	int rc = loc_server_register(NAME, rd_connection);
-	if (rc < 0) {
-		printf("%s: Unable to register driver (%d)\n", NAME, rc);
+	printf("%s: Found RAM disk at %p, %" PRIun " bytes\n", NAME,
+	    (void *) addr_phys, size);
+	
+	ret = loc_server_register(NAME, rd_connection);
+	if (ret < 0) {
+		printf("%s: Unable to register driver (%d)\n", NAME, ret);
 		return false;
 	}
 	
 	service_id_t service_id;
-	if (loc_service_register("bd/initrd", &service_id) != EOK) {
+	ret = loc_service_register("bd/initrd", &service_id);
+	if (ret != EOK) {
 		printf("%s: Unable to register device service\n", NAME);
 		return false;
Index: uspace/srv/devman/devman.c
===================================================================
--- uspace/srv/devman/devman.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/devman/devman.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -794,4 +794,7 @@
 	case EOK:
 		dev->state = DEVICE_USABLE;
+		exch = async_exchange_begin(drv->sess);
+		async_msg_1(exch, DRIVER_DEV_ADDED, dev->handle);
+		async_exchange_end(exch);
 		break;
 	case ENOENT:
@@ -1066,4 +1069,7 @@
 	
 	link = hash_table_find(&tree->devman_devices, &key);
+	if (link == NULL)
+		return NULL;
+	
 	return hash_table_get_instance(link, dev_node_t, devman_dev);
 }
Index: uspace/srv/devman/main.c
===================================================================
--- uspace/srv/devman/main.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/devman/main.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -490,4 +490,6 @@
 	if (rc == EOK) {
 		loc_service_add_to_cat(fun->service_id, cat_id);
+		log_msg(LVL_NOTE, "Function `%s' added to category `%s'.",
+		    fun->pathname, cat_name);
 	} else {
 		log_msg(LVL_ERROR, "Failed adding function `%s' to category "
@@ -495,11 +497,8 @@
 	}
 	
-	log_msg(LVL_NOTE, "Function `%s' added to category `%s'.",
-	    fun->pathname, cat_name);
-
 	fibril_rwlock_read_unlock(&device_tree.rwlock);
 	fun_del_ref(fun);
-
-	async_answer_0(callid, EOK);
+	
+	async_answer_0(callid, rc);
 }
 
@@ -635,4 +634,7 @@
 				fibril_rwlock_read_unlock(&device_tree.rwlock);
 				dev_del_ref(dev);
+				if (gone_rc == EOK)
+					gone_rc = ENOTSUP;
+				async_answer_0(callid, gone_rc);
 				return;
 			}
Index: uspace/srv/fs/cdfs/cdfs.c
===================================================================
--- uspace/srv/fs/cdfs/cdfs.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/cdfs/cdfs.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -52,4 +52,5 @@
 	.concurrent_read_write = false,
 	.write_retains_size = false,
+	.instance = 0,
 };
 
@@ -58,4 +59,13 @@
 	printf("%s: HelenOS cdfs file system server\n", NAME);
 	
+	if (argc == 3) {
+		if (!str_cmp(argv[1], "--instance"))
+			cdfs_vfs_info.instance = strtol(argv[2], NULL, 10);
+		else {
+			printf(NAME " Unrecognized parameters");
+			return -1;
+		}
+	}
+
 	if (!cdfs_init()) {
 		printf("%s: failed to initialize cdfs\n", NAME);
Index: uspace/srv/fs/exfat/exfat.c
===================================================================
--- uspace/srv/fs/exfat/exfat.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/exfat/exfat.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -54,5 +54,6 @@
 	.name = NAME,
 	.concurrent_read_write = false,
-	.write_retains_size = false,	
+	.write_retains_size = false,
+	.instance = 0,
 };
 
@@ -60,4 +61,13 @@
 {
 	printf(NAME ": HelenOS exFAT file system server\n");
+
+	if (argc == 3) {
+		if (!str_cmp(argv[1], "--instance"))
+			exfat_vfs_info.instance = strtol(argv[2], NULL, 10);
+		else {
+			printf(NAME " Unrecognized parameters");
+			return -1;
+		}
+	}
 
 	int rc = exfat_idx_init();
Index: uspace/srv/fs/exfat/exfat_directory.c
===================================================================
--- uspace/srv/fs/exfat/exfat_directory.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/exfat/exfat_directory.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -92,6 +92,8 @@
 	int rc = EOK;
 	
-	if (di->b)
+	if (di->b) {
 		rc = block_put(di->b);
+		di->b = NULL;
+	}
 	
 	return rc;
@@ -101,5 +103,5 @@
 {
 	uint32_t i;
-	int rc;
+	int rc = EOK;
 
 	i = (di->pos * sizeof(exfat_dentry_t)) / BPS(di->bs);
@@ -108,5 +110,5 @@
 
 	if (di->b && di->bnum != i) {
-		block_put(di->b);
+		rc = block_put(di->b);
 		di->b = NULL;
 	}
@@ -126,5 +128,5 @@
 		di->bnum = i;
 	}
-	return EOK;
+	return rc;
 }
 
@@ -285,6 +287,8 @@
 	for (i = 0; i < count; i++) {
 		rc = exfat_directory_get(di, &de);
-		if (rc != EOK)
-			return rc;
+		if (rc != EOK) {
+			free(array);
+			return rc;
+		}
 		array[i] = *de;
 		rc = exfat_directory_next(di);
@@ -312,6 +316,8 @@
 	for (i = 0; i < count; i++) {
 		rc = exfat_directory_get(di, &de);
-		if (rc != EOK)
-			return rc;
+		if (rc != EOK) {
+			free(array);
+			return rc;
+		}
 		*de = array[i];
 		di->b->dirty = true;
@@ -424,5 +430,4 @@
 
 		di->b->dirty = true;
-		sname += chars;
 	}
 	
@@ -434,4 +439,6 @@
 	int rc, count;
 	exfat_dentry_t *de;
+
+	di->pos = pos;
 
 	rc = exfat_directory_get(di, &de);
Index: uspace/srv/fs/ext2fs/ext2fs.c
===================================================================
--- uspace/srv/fs/ext2fs/ext2fs.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/ext2fs/ext2fs.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -52,4 +52,5 @@
 vfs_info_t ext2fs_vfs_info = {
 	.name = NAME,
+	.instance = 0,
 };
 
@@ -57,4 +58,13 @@
 {
 	printf(NAME ": HelenOS EXT2 file system server\n");
+
+	if (argc == 3) {
+		if (!str_cmp(argv[1], "--instance"))
+			ext2fs_vfs_info.instance = strtol(argv[2], NULL, 10);
+		else {
+			printf(NAME " Unrecognized parameters");
+			return -1;
+		}
+	}
 	
 	async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
Index: uspace/srv/fs/fat/fat.c
===================================================================
--- uspace/srv/fs/fat/fat.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/fat/fat.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -54,5 +54,6 @@
 	.name = NAME,
 	.concurrent_read_write = false,
-	.write_retains_size = false,	
+	.write_retains_size = false,
+	.instance = 0,
 };
 
@@ -61,4 +62,13 @@
 	printf(NAME ": HelenOS FAT file system server\n");
 	
+	if (argc == 3) {
+		if (!str_cmp(argv[1], "--instance"))
+			fat_vfs_info.instance = strtol(argv[2], NULL, 10);
+		else {
+			printf(NAME " Unrecognized parameters");
+			return -1;
+		}
+	}
+
 	int rc = fat_idx_init();
 	if (rc != EOK)
Index: uspace/srv/fs/fat/fat.h
===================================================================
--- uspace/srv/fs/fat/fat.h	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/fat/fat.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -141,4 +141,18 @@
 } __attribute__ ((packed)) fat_bs_t;
 
+#define FAT32_FSINFO_SIG1	"RRaA"
+#define FAT32_FSINFO_SIG2	"rrAa"
+#define FAT32_FSINFO_SIG3	"\x00\x00\x55\xaa"
+
+typedef struct {
+	uint8_t	sig1[4];
+	uint8_t res1[480];
+	uint8_t sig2[4];
+	uint32_t free_clusters;
+	uint32_t last_allocated_cluster;
+	uint8_t res2[12];
+	uint8_t sig3[4];
+} __attribute__ ((packed)) fat32_fsinfo_t;
+
 typedef enum {
 	FAT_INVALID,
@@ -230,4 +244,8 @@
 } fat_node_t;
 
+typedef struct {
+	bool lfn_enabled;
+} fat_instance_t;
+
 extern vfs_out_ops_t fat_ops;
 extern libfs_ops_t fat_libfs_ops;
Index: uspace/srv/fs/fat/fat_directory.c
===================================================================
--- uspace/srv/fs/fat/fat_directory.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/fat/fat_directory.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -262,5 +262,10 @@
 {
 	int rc;
-	bool enable_lfn = true; /* TODO: make this a mount option */
+	void *data;
+	fat_instance_t *instance;
+
+	rc = fs_instance_get(di->nodep->idx->service_id, &data);
+	assert(rc == EOK);
+	instance = (fat_instance_t *) data;
 	
 	if (fat_valid_short_name(name)) {
@@ -277,5 +282,5 @@
 		rc = fat_directory_write_dentry(di, de);
 		return rc;
-	} else if (enable_lfn && fat_valid_name(name)) {
+	} else if (instance->lfn_enabled && fat_valid_name(name)) {
 		/* We should create long entries to store name */
 		int long_entry_count;
@@ -292,5 +297,5 @@
 		if (lfn_size % FAT_LFN_ENTRY_SIZE)
 			long_entry_count++;
-		rc = fat_directory_lookup_free(di, long_entry_count+1);
+		rc = fat_directory_lookup_free(di, long_entry_count + 1);
 		if (rc != EOK)
 			return rc;
@@ -328,5 +333,5 @@
 		FAT_LFN_ORDER(d) |= FAT_LFN_LAST;
 
-		rc = fat_directory_seek(di, start_pos+long_entry_count);
+		rc = fat_directory_seek(di, start_pos + long_entry_count);
 		return rc;
 	}
Index: uspace/srv/fs/fat/fat_ops.c
===================================================================
--- uspace/srv/fs/fat/fat_ops.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/fat/fat_ops.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -871,22 +871,37 @@
     aoff64_t *size, unsigned *linkcnt)
 {
-	enum cache_mode cmode;
+	enum cache_mode cmode = CACHE_MODE_WB;
 	fat_bs_t *bs;
-	int rc;
-
-	/* Check for option enabling write through. */
-	if (str_cmp(opts, "wtcache") == 0)
-		cmode = CACHE_MODE_WT;
-	else
-		cmode = CACHE_MODE_WB;
+	fat_instance_t *instance;
+	int rc;
+
+	instance = malloc(sizeof(fat_instance_t));
+	if (!instance)
+		return ENOMEM;
+	instance->lfn_enabled = true;
+
+	/* Parse mount options. */
+	char *mntopts = (char *) opts;
+	char *saveptr;
+	char *opt;
+	while ((opt = strtok_r(mntopts, " ,", &saveptr)) != NULL) {
+		if (str_cmp(opt, "wtcache") == 0)
+			cmode = CACHE_MODE_WT;
+		else if (str_cmp(opt, "nolfn") == 0)
+			instance->lfn_enabled = false;
+		mntopts = NULL;
+	}
 
 	/* initialize libblock */
 	rc = block_init(EXCHANGE_SERIALIZE, service_id, BS_SIZE);
-	if (rc != EOK)
-		return rc;
+	if (rc != EOK) {
+		free(instance);
+		return rc;
+	}
 
 	/* prepare the boot block */
 	rc = block_bb_read(service_id, BS_BLOCK);
 	if (rc != EOK) {
+		free(instance);
 		block_fini(service_id);
 		return rc;
@@ -897,4 +912,5 @@
 	
 	if (BPS(bs) != BS_SIZE) {
+		free(instance);
 		block_fini(service_id);
 		return ENOTSUP;
@@ -904,4 +920,5 @@
 	rc = block_cache_init(service_id, BPS(bs), 0 /* XXX */, cmode);
 	if (rc != EOK) {
+		free(instance);
 		block_fini(service_id);
 		return rc;
@@ -911,4 +928,5 @@
 	rc = fat_sanity_check(bs, service_id);
 	if (rc != EOK) {
+		free(instance);
 		(void) block_cache_fini(service_id);
 		block_fini(service_id);
@@ -918,4 +936,5 @@
 	rc = fat_idx_init_by_service_id(service_id);
 	if (rc != EOK) {
+		free(instance);
 		(void) block_cache_fini(service_id);
 		block_fini(service_id);
@@ -926,4 +945,5 @@
 	fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t));
 	if (!rfn) {
+		free(instance);
 		(void) block_cache_fini(service_id);
 		block_fini(service_id);
@@ -935,4 +955,5 @@
 	fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));
 	if (!rootp) {
+		free(instance);
 		free(rfn);
 		(void) block_cache_fini(service_id);
@@ -945,4 +966,5 @@
 	fat_idx_t *ridxp = fat_idx_get_by_pos(service_id, FAT_CLST_ROOTPAR, 0);
 	if (!ridxp) {
+		free(instance);
 		free(rfn);
 		free(rootp);
@@ -964,4 +986,6 @@
 		rc = fat_clusters_get(&clusters, bs, service_id, rootp->firstc);
 		if (rc != EOK) {
+			fibril_mutex_unlock(&ridxp->lock);
+			free(instance);
 			free(rfn);
 			free(rootp);
@@ -975,4 +999,16 @@
 		rootp->size = RDE(bs) * sizeof(fat_dentry_t);
 
+	rc = fs_instance_create(service_id, instance);
+	if (rc != EOK) {
+		fibril_mutex_unlock(&ridxp->lock);
+		free(instance);
+		free(rfn);
+		free(rootp);
+		(void) block_cache_fini(service_id);
+		block_fini(service_id);
+		fat_idx_fini_by_service_id(service_id);
+		return rc;
+	}
+
 	rootp->idx = ridxp;
 	ridxp->nodep = rootp;
@@ -989,9 +1025,43 @@
 }
 
+static int fat_update_fat32_fsinfo(service_id_t service_id)
+{
+	fat_bs_t *bs;
+	fat32_fsinfo_t *info;
+	block_t *b;
+	int rc;
+
+	bs = block_bb_get(service_id);
+	assert(FAT_IS_FAT32(bs));
+
+	rc = block_get(&b, service_id, uint16_t_le2host(bs->fat32.fsinfo_sec),
+	    BLOCK_FLAGS_NONE);
+	if (rc != EOK)
+		return rc;
+
+	info = (fat32_fsinfo_t *) b->data;
+
+	if (bcmp(info->sig1, FAT32_FSINFO_SIG1, sizeof(info->sig1)) ||
+	    bcmp(info->sig2, FAT32_FSINFO_SIG2, sizeof(info->sig2)) ||
+	    bcmp(info->sig3, FAT32_FSINFO_SIG3, sizeof(info->sig3))) {
+		(void) block_put(b);
+		return EINVAL;
+	}
+
+	/* For now, invalidate the counter. */
+	info->free_clusters = host2uint16_t_le(-1);
+
+	b->dirty = true;
+	return block_put(b);
+}
+
 static int fat_unmounted(service_id_t service_id)
 {
 	fs_node_t *fn;
 	fat_node_t *nodep;
-	int rc;
+	fat_bs_t *bs;
+	int rc;
+
+	bs = block_bb_get(service_id);
 
 	rc = fat_root_get(&fn, service_id);
@@ -1007,4 +1077,11 @@
 		(void) fat_node_put(fn);
 		return EBUSY;
+	}
+
+	if (FAT_IS_FAT32(bs)) {
+		/*
+		 * Attempt to update the FAT32 FS info.
+		 */
+		(void) fat_update_fat32_fsinfo(service_id);
 	}
 
@@ -1024,4 +1101,10 @@
 	(void) block_cache_fini(service_id);
 	block_fini(service_id);
+
+	void *data;
+	if (fs_instance_get(service_id, &data) == EOK) {
+		fs_instance_destroy(service_id);
+		free(data);
+	}
 
 	return EOK;
Index: uspace/srv/fs/locfs/locfs.c
===================================================================
--- uspace/srv/fs/locfs/locfs.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/locfs/locfs.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -55,4 +55,5 @@
 	.concurrent_read_write = false,
 	.write_retains_size = false,
+	.instance = 0,
 };
 
@@ -61,4 +62,14 @@
 	printf("%s: HelenOS Device Filesystem\n", NAME);
 	
+	if (argc == 3) {
+		if (!str_cmp(argv[1], "--instance"))
+			locfs_vfs_info.instance = strtol(argv[2], NULL, 10);
+		else {
+			printf(NAME " Unrecognized parameters");
+			return -1;
+		}
+	}
+
+
 	if (!locfs_init()) {
 		printf("%s: failed to initialize locfs\n", NAME);
Index: uspace/srv/fs/locfs/locfs_ops.c
===================================================================
--- uspace/srv/fs/locfs/locfs_ops.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/locfs/locfs_ops.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -593,4 +593,8 @@
 		sysarg_t rc;
 		async_wait_for(msg, &rc);
+
+		/* Do not propagate EHANGUP back to VFS. */
+		if ((int) rc == EHANGUP)
+			rc = ENOTSUP;
 		
 		*rbytes = IPC_GET_ARG1(answer);
@@ -655,4 +659,8 @@
 		sysarg_t rc;
 		async_wait_for(msg, &rc);
+
+		/* Do not propagate EHANGUP back to VFS. */
+		if ((int) rc == EHANGUP)
+			rc = ENOTSUP;
 		
 		*wbytes = IPC_GET_ARG1(answer);
Index: uspace/srv/fs/mfs/mfs.c
===================================================================
--- uspace/srv/fs/mfs/mfs.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/mfs/mfs.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -39,4 +39,6 @@
 
 #include <ipc/services.h>
+#include <stdlib.h>
+#include <str.h>
 #include <ns.h>
 #include <async.h>
@@ -52,4 +54,5 @@
 	.concurrent_read_write = false,
 	.write_retains_size = false,
+	.instance = 0,
 };
 
@@ -60,6 +63,16 @@
 	printf(NAME ": HelenOS Minix file system server\n");
 
+	if (argc == 3) {
+		if (!str_cmp(argv[1], "--instance"))
+			mfs_vfs_info.instance = strtol(argv[2], NULL, 10);
+		else {
+			printf(NAME " Unrecognized parameters");
+			rc = -1;
+			goto err;
+		}
+	}
+
 	async_sess_t *vfs_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
-				SERVICE_VFS, 0, 0);
+	    SERVICE_VFS, 0, 0);
 
 	if (!vfs_sess) {
Index: uspace/srv/fs/mfs/mfs.h
===================================================================
--- uspace/srv/fs/mfs/mfs.h	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/mfs/mfs.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -48,5 +48,5 @@
 #define NAME		"mfs"
 
-//#define DEBUG_MODE
+/* #define DEBUG_MODE */
 
 #define min(a, b)	((a) < (b) ? (a) : (b))
@@ -71,5 +71,5 @@
 } mfs_version_t;
 
-/*Generic MinixFS superblock*/
+/* Generic MinixFS superblock */
 struct mfs_sb_info {
 	uint32_t ninodes;
@@ -84,5 +84,5 @@
 	uint16_t state;
 
-	/*The following fields do not exist on disk but only in memory*/
+	/* The following fields do not exist on disk but only in memory */
 	unsigned long itable_size;
 	mfs_version_t fs_version;
@@ -97,5 +97,5 @@
 };
 
-/*Generic MinixFS inode*/
+/* Generic MinixFS inode */
 struct mfs_ino_info {
 	uint16_t	i_mode;
@@ -107,29 +107,28 @@
 	int32_t		i_mtime;
 	int32_t		i_ctime;
-	/*Block numbers for direct zones*/
+	/* Block numbers for direct zones */
 	uint32_t	i_dzone[V2_NR_DIRECT_ZONES];
-	/*Block numbers for indirect zones*/
+	/* Block numbers for indirect zones */
 	uint32_t	i_izone[V2_NR_INDIRECT_ZONES];
 
-	/*The following fields do not exist on disk but only in memory*/
+	/* The following fields do not exist on disk but only in memory */
 	bool dirty;
 	fs_index_t index;
 };
 
-/*Generic MFS directory entry*/
+/* Generic MFS directory entry */
 struct mfs_dentry_info {
 	uint32_t d_inum;
 	char d_name[MFS3_MAX_NAME_LEN + 1];
 
-	/*The following fields do not exist on disk but only in memory*/
-
-	/*Index of the dentry in the list*/
+	/* The following fields do not exist on disk but only in memory */
+
+	/* Index of the dentry in the list */
 	unsigned index;
-	/*Pointer to the node at witch the dentry belongs*/
+	/* Pointer to the node at witch the dentry belongs */
 	struct mfs_node *node;
 };
 
 struct mfs_instance {
-	link_t link;
 	service_id_t service_id;
 	struct mfs_sb_info *sbi;
@@ -137,5 +136,5 @@
 };
 
-/*MinixFS node in core*/
+/* MinixFS node in core */
 struct mfs_node {
 	struct mfs_ino_info *ino_i;
@@ -146,5 +145,5 @@
 };
 
-/*mfs_ops.c*/
+/* mfs_ops.c */
 extern vfs_out_ops_t mfs_ops;
 extern libfs_ops_t mfs_libfs_ops;
@@ -153,8 +152,8 @@
 mfs_global_init(void);
 
-/*mfs_inode.c*/
+/* mfs_inode.c */
 extern int
 mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
-	  fs_index_t index);
+    fs_index_t index);
 
 extern int
@@ -164,5 +163,5 @@
 mfs_inode_shrink(struct mfs_node *mnode, size_t size_shrink);
 
-/*mfs_rw.c*/
+/* mfs_rw.c */
 extern int
 mfs_read_map(uint32_t *b, const struct mfs_node *mnode, const uint32_t pos);
@@ -170,13 +169,13 @@
 extern int
 mfs_write_map(struct mfs_node *mnode, uint32_t pos, uint32_t new_zone,
-	  uint32_t *old_zone);
+    uint32_t *old_zone);
 
 extern int
 mfs_prune_ind_zones(struct mfs_node *mnode, size_t new_size);
 
-/*mfs_dentry.c*/
+/* mfs_dentry.c */
 extern int
 mfs_read_dentry(struct mfs_node *mnode,
-		     struct mfs_dentry_info *d_info, unsigned index);
+    struct mfs_dentry_info *d_info, unsigned index);
 
 extern int
@@ -189,5 +188,5 @@
 mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum);
 
-/*mfs_balloc.c*/
+/* mfs_balloc.c */
 extern int
 mfs_alloc_inode(struct mfs_instance *inst, uint32_t *inum);
@@ -202,5 +201,5 @@
 mfs_free_zone(struct mfs_instance *inst, uint32_t zone);
 
-/*mfs_utils.c*/
+/* mfs_utils.c */
 extern uint16_t
 conv16(bool native, uint16_t n);
Index: uspace/srv/fs/mfs/mfs_balloc.c
===================================================================
--- uspace/srv/fs/mfs/mfs_balloc.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/mfs/mfs_balloc.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -36,5 +36,5 @@
 static int
 find_free_bit_and_set(bitchunk_t *b, const int bsize,
-		      const bool native, unsigned start_bit);
+    const bool native, unsigned start_bit);
 
 static int
@@ -129,19 +129,19 @@
 		if (idx > sbi->nzones) {
 			printf(NAME ": Error! Trying to free beyond the" \
-			       "bitmap max size\n");
+			    "bitmap max size\n");
 			return -1;
 		}
 	} else {
-		/*bid == BMAP_INODE*/
+		/* bid == BMAP_INODE */
 		search = &sbi->isearch;
 		start_block = 2;
 		if (idx > sbi->ninodes) {
 			printf(NAME ": Error! Trying to free beyond the" \
-			       "bitmap max size\n");
+			    "bitmap max size\n");
 			return -1;
 		}
 	}
 
-	/*Compute the bitmap block*/
+	/* Compute the bitmap block */
 	uint32_t block = idx / (sbi->block_size * 8) + start_block;
 
@@ -150,5 +150,5 @@
 		goto out_err;
 
-	/*Compute the bit index in the block*/
+	/* Compute the bit index in the block */
 	idx %= (sbi->block_size * 8);
 	bitchunk_t *ptr = b->data;
@@ -198,5 +198,5 @@
 		limit = sbi->nzones - sbi->firstdatazone - 1;
 	} else {
-		/*bid == BMAP_INODE*/
+		/* bid == BMAP_INODE */
 		search = &sbi->isearch;
 		start_block = 2;
@@ -212,5 +212,5 @@
 	for (i = *search / bits_per_block; i < nblocks; ++i) {
 		r = block_get(&b, inst->service_id, i + start_block,
-			      BLOCK_FLAGS_NONE);
+		    BLOCK_FLAGS_NONE);
 
 		if (r != EOK)
@@ -220,7 +220,7 @@
 
 		freebit = find_free_bit_and_set(b->data, sbi->block_size,
-						sbi->native, tmp);
+		    sbi->native, tmp);
 		if (freebit == -1) {
-			/*No free bit in this block*/
+			/* No free bit in this block */
 			r = block_put(b);
 			if (r != EOK)
@@ -229,8 +229,8 @@
 		}
 
-		/*Free bit found in this block, compute the real index*/
+		/* Free bit found in this block, compute the real index */
 		*idx = freebit + bits_per_block * i;
 		if (*idx > limit) {
-			/*Index is beyond the limit, it is invalid*/
+			/* Index is beyond the limit, it is invalid */
 			r = block_put(b);
 			if (r != EOK)
@@ -246,10 +246,10 @@
 
 	if (*search > 0) {
-		/*Repeat the search from the first bitmap block*/
+		/* Repeat the search from the first bitmap block */
 		*search = 0;
 		goto retry;
 	}
 
-	/*Free bit not found, return error*/
+	/* Free bit not found, return error */
 	return ENOSPC;
 
@@ -260,5 +260,5 @@
 static int
 find_free_bit_and_set(bitchunk_t *b, const int bsize,
-		      const bool native, unsigned start_bit)
+    const bool native, unsigned start_bit)
 {
 	int r = -1;
@@ -268,7 +268,8 @@
 
 	for (i = start_bit / chunk_bits;
-	     i < bsize / sizeof(bitchunk_t); ++i) {
+	    i < bsize / sizeof(bitchunk_t); ++i) {
+
 		if (!(~b[i])) {
-			/*No free bit in this chunk*/
+			/* No free bit in this chunk */
 			continue;
 		}
Index: uspace/srv/fs/mfs/mfs_dentry.c
===================================================================
--- uspace/srv/fs/mfs/mfs_dentry.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/mfs/mfs_dentry.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -44,5 +44,5 @@
 int
 mfs_read_dentry(struct mfs_node *mnode,
-		     struct mfs_dentry_info *d_info, unsigned index)
+    struct mfs_dentry_info *d_info, unsigned index)
 {
 	const struct mfs_instance *inst = mnode->instance;
@@ -57,5 +57,5 @@
 
 	if (block == 0) {
-		/*End of the dentries list*/
+		/* End of the dentries list */
 		r = EOK;
 		goto out_err;
@@ -79,10 +79,10 @@
 	} else {
 		const int namelen = longnames ? MFS_L_MAX_NAME_LEN :
-				    MFS_MAX_NAME_LEN;
+		    MFS_MAX_NAME_LEN;
 
 		struct mfs_dentry *d;
 
 		d = b->data + dentry_off * (longnames ? MFSL_DIRSIZE :
-					    MFS_DIRSIZE);
+		    MFS_DIRSIZE);
 		d_info->d_inum = conv16(sbi->native, d->d_inum);
 		memcpy(d_info->d_name, d->d_name, namelen);
@@ -101,7 +101,7 @@
 /**Write a directory entry on disk.
  *
- * @param d_info	Pointer to the directory entry structure to write on disk.
- *
- * @return		EOK on success or a negative error code.
+ * @param d_info Pointer to the directory entry structure to write on disk.
+ *
+ * @return	 EOK on success or a negative error code.
  */
 int
@@ -168,5 +168,5 @@
 		return ENAMETOOLONG;
 
-	/*Search the directory entry to be removed*/
+	/* Search the directory entry to be removed */
 	unsigned i;
 	for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize ; ++i) {
@@ -178,5 +178,6 @@
 
 		if (name_len == d_name_len &&
-				!bcmp(d_info.d_name, d_name, name_len)) {
+		    !bcmp(d_info.d_name, d_name, name_len)) {
+
 			d_info.d_inum = 0;
 			r = mfs_write_dentry(&d_info);
@@ -197,5 +198,6 @@
  */
 int
-mfs_insert_dentry(struct mfs_node *mnode, const char *d_name, fs_index_t d_inum)
+mfs_insert_dentry(struct mfs_node *mnode, const char *d_name,
+    fs_index_t d_inum)
 {
 	int r;
@@ -209,5 +211,5 @@
 		return ENAMETOOLONG;
 
-	/*Search for an empty dentry*/
+	/* Search for an empty dentry */
 	unsigned i;
 	for (i = 0; i < mnode->ino_i->i_size / sbi->dirsize; ++i) {
@@ -217,5 +219,5 @@
 
 		if (d_info.d_inum == 0) {
-			/*This entry is not used*/
+			/* This entry is not used */
 			empty_dentry_found = true;
 			break;
@@ -231,5 +233,5 @@
 
 		if (b == 0) {
-			/*Increase the inode size*/
+			/* Increase the inode size */
 
 			uint32_t dummy;
Index: uspace/srv/fs/mfs/mfs_inode.c
===================================================================
--- uspace/srv/fs/mfs/mfs_inode.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/mfs/mfs_inode.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -42,9 +42,9 @@
 static int
 mfs_read_inode_raw(const struct mfs_instance *instance,
-		struct mfs_ino_info **ino_ptr, uint16_t inum);
+    struct mfs_ino_info **ino_ptr, uint16_t inum);
 
 static int
 mfs2_read_inode_raw(const struct mfs_instance *instance,
-		struct mfs_ino_info **ino_ptr, uint32_t inum);
+    struct mfs_ino_info **ino_ptr, uint32_t inum);
 
 /**Read a MINIX inode from disk
@@ -59,5 +59,5 @@
 int
 mfs_get_inode(struct mfs_instance *inst, struct mfs_ino_info **ino_i,
-	  fs_index_t index)
+    fs_index_t index)
 {
 	struct mfs_sb_info *sbi = inst->sbi;
@@ -65,8 +65,8 @@
 
 	if (sbi->fs_version == MFS_VERSION_V1) {
-		/*Read a MFS V1 inode*/
+		/* Read a MFS V1 inode */
 		r = mfs_read_inode_raw(inst, ino_i, index);
 	} else {
-		/*Read a MFS V2/V3 inode*/
+		/* Read a MFS V2/V3 inode */
 		r = mfs2_read_inode_raw(inst, ino_i, index);
 	}
@@ -77,5 +77,6 @@
 static int
 mfs_read_inode_raw(const struct mfs_instance *instance,
-		struct mfs_ino_info **ino_ptr, uint16_t inum) {
+    struct mfs_ino_info **ino_ptr, uint16_t inum)
+{
 	struct mfs_inode *ino;
 	struct mfs_ino_info *ino_i = NULL;
@@ -86,5 +87,5 @@
 	sbi = instance->sbi;
 
-	/*inode 0 does not exist*/
+	/* inode 0 does not exist */
 	inum -= 1;
 
@@ -101,6 +102,7 @@
 
 	r = block_get(&b, instance->service_id,
-		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE);
+	    itable_off + inum / sbi->ino_per_block,
+	    BLOCK_FLAGS_NONE);
+
 	if (r != EOK)
 		goto out_err;
@@ -134,5 +136,6 @@
 static int
 mfs2_read_inode_raw(const struct mfs_instance *instance,
-		struct mfs_ino_info **ino_ptr, uint32_t inum) {
+    struct mfs_ino_info **ino_ptr, uint32_t inum)
+{
 	struct mfs2_inode *ino;
 	struct mfs_ino_info *ino_i = NULL;
@@ -150,5 +153,5 @@
 	sbi = instance->sbi;
 
-	/*inode 0 does not exist*/
+	/* inode 0 does not exist */
 	inum -= 1;
 
@@ -157,6 +160,7 @@
 
 	r = block_get(&b, instance->service_id,
-		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE);
+	    itable_off + inum / sbi->ino_per_block,
+	    BLOCK_FLAGS_NONE);
+
 	if (r != EOK)
 		goto out_err;
@@ -231,6 +235,6 @@
 
 	r = block_get(&b, mnode->instance->service_id,
-		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE);
+	    itable_off + inum / sbi->ino_per_block,
+	    BLOCK_FLAGS_NONE);
 
 	if (r != EOK)
@@ -274,6 +278,6 @@
 
 	r = block_get(&b, mnode->instance->service_id,
-		      itable_off + inum / sbi->ino_per_block,
-		      BLOCK_FLAGS_NONE);
+	    itable_off + inum / sbi->ino_per_block,
+	    BLOCK_FLAGS_NONE);
 
 	if (r != EOK)
@@ -322,5 +326,5 @@
 
 	if (size_shrink == 0) {
-		/*File is empty*/
+		/* Nothing to be done */
 		return EOK;
 	}
@@ -333,5 +337,5 @@
 	ino_i->dirty = true;
 
-	/*Compute the number of zones to free*/
+	/* Compute the number of zones to free */
 	unsigned zones_to_free;
 
@@ -354,5 +358,5 @@
 
 		if (old_zone == 0)
-			continue; /*Sparse block*/
+			continue; /* Sparse block */
 
 		r = mfs_free_zone(mnode->instance, old_zone);
Index: uspace/srv/fs/mfs/mfs_ops.c
===================================================================
--- uspace/srv/fs/mfs/mfs_ops.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/mfs/mfs_ops.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -43,8 +43,7 @@
 
 static bool check_magic_number(uint16_t magic, bool *native,
-			       mfs_version_t *version, bool *longfilenames);
+    mfs_version_t *version, bool *longfilenames);
 static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
-			     fs_index_t index);
-
+    fs_index_t index);
 static int mfs_node_put(fs_node_t *fsnode);
 static int mfs_node_open(fs_node_t *fsnode);
@@ -64,15 +63,13 @@
 static hash_index_t open_nodes_hash(unsigned long key[]);
 static int open_nodes_compare(unsigned long key[], hash_count_t keys,
-		link_t *item);
+    link_t *item);
 static void open_nodes_remove_cb(link_t *link);
-
 static int mfs_node_get(fs_node_t **rfn, service_id_t service_id,
-			fs_index_t index);
-static int
-mfs_instance_get(service_id_t service_id, struct mfs_instance **instance);
-
-
-static LIST_INITIALIZE(inst_list);
-static FIBRIL_MUTEX_INITIALIZE(inst_list_mutex);
+    fs_index_t index);
+static int mfs_instance_get(service_id_t service_id,
+    struct mfs_instance **instance);
+static int mfs_check_sanity(struct mfs_sb_info *sbi);
+static bool is_power_of_two(uint32_t n);
+
 static hash_table_t open_nodes;
 static FIBRIL_MUTEX_INITIALIZE(open_nodes_lock);
@@ -98,5 +95,6 @@
 
 /* Hash table interface for open nodes hash table */
-static hash_index_t open_nodes_hash(unsigned long key[])
+static hash_index_t
+open_nodes_hash(unsigned long key[])
 {
 	/* TODO: This is very simple and probably can be improved */
@@ -104,6 +102,7 @@
 }
 
-static int open_nodes_compare(unsigned long key[], hash_count_t keys,
-		link_t *item)
+static int
+open_nodes_compare(unsigned long key[], hash_count_t keys,
+    link_t *item)
 {
 	struct mfs_node *mnode = hash_table_get_instance(item, struct mfs_node, link);
@@ -120,5 +119,6 @@
 }
 
-static void open_nodes_remove_cb(link_t *link)
+static void
+open_nodes_remove_cb(link_t *link)
 {
 	/* We don't use remove callback for this hash table */
@@ -131,8 +131,9 @@
 };
 
-int mfs_global_init(void)
+int
+mfs_global_init(void)
 {
 	if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS,
-			OPEN_NODES_KEYS, &open_nodes_ops)) {
+	    OPEN_NODES_KEYS, &open_nodes_ops)) {
 		return ENOMEM;
 	}
@@ -142,11 +143,11 @@
 static int
 mfs_mounted(service_id_t service_id, const char *opts, fs_index_t *index,
-		aoff64_t *size, unsigned *linkcnt)
+    aoff64_t *size, unsigned *linkcnt)
 {
 	enum cache_mode cmode;
-	struct mfs_superblock *sb;
-	struct mfs3_superblock *sb3;
-	struct mfs_sb_info *sbi;
-	struct mfs_instance *instance;
+	struct mfs_superblock *sb = NULL;
+	struct mfs3_superblock *sb3 = NULL;
+	struct mfs_sb_info *sbi = NULL;
+	struct mfs_instance *instance = NULL;
 	bool native, longnames;
 	mfs_version_t version;
@@ -165,60 +166,47 @@
 		return rc;
 
-	/*Allocate space for generic MFS superblock*/
+	/* Allocate space for generic MFS superblock */
 	sbi = malloc(sizeof(*sbi));
 	if (!sbi) {
-		block_fini(service_id);
-		return ENOMEM;
-	}
-
-	/*Allocate space for filesystem instance*/
+		rc = ENOMEM;
+		goto out_error;
+	}
+
+	/* Allocate space for filesystem instance */
 	instance = malloc(sizeof(*instance));
 	if (!instance) {
-		free(sbi);
-		block_fini(service_id);
-		return ENOMEM;
-	}
-
-	instance->open_nodes_cnt = 0;
+		rc = ENOMEM;
+		goto out_error;
+	}
 
 	sb = malloc(MFS_SUPERBLOCK_SIZE);
 	if (!sb) {
-		free(instance);
-		free(sbi);
-		block_fini(service_id);
-		return ENOMEM;
+		rc = ENOMEM;
+		goto out_error;
 	}
 
 	/* Read the superblock */
 	rc = block_read_direct(service_id, MFS_SUPERBLOCK << 1, 2, sb);
-	if (rc != EOK) {
-		free(instance);
-		free(sbi);
-		free(sb);
-		block_fini(service_id);
-		return rc;
-	}
+	if (rc != EOK)
+		goto out_error;
 
 	sb3 = (struct mfs3_superblock *) sb;
 
 	if (check_magic_number(sb->s_magic, &native, &version, &longnames)) {
-		/*This is a V1 or V2 Minix filesystem*/
+		/* This is a V1 or V2 Minix filesystem */
 		magic = sb->s_magic;
 	} else if (check_magic_number(sb3->s_magic, &native, &version, &longnames)) {
-		/*This is a V3 Minix filesystem*/
+		/* This is a V3 Minix filesystem */
 		magic = sb3->s_magic;
 	} else {
-		/*Not recognized*/
+		/* Not recognized */
 		mfsdebug("magic number not recognized\n");
-		free(instance);
-		free(sbi);
-		free(sb);
-		block_fini(service_id);
-		return ENOTSUP;
+		rc = ENOTSUP;
+		goto out_error;
 	}
 
 	mfsdebug("magic number recognized = %04x\n", magic);
 
-	/*Fill superblock info structure*/
+	/* Fill superblock info structure */
 
 	sbi->fs_version = version;
@@ -258,29 +246,42 @@
 		sbi->dirsize = longnames ? MFSL_DIRSIZE : MFS_DIRSIZE;
 		sbi->max_name_len = longnames ? MFS_L_MAX_NAME_LEN :
-				    MFS_MAX_NAME_LEN;
-	}
+		    MFS_MAX_NAME_LEN;
+	}
+
+	if (sbi->log2_zone_size != 0) {
+		/* In MFS, file space is allocated per zones.
+		 * Zones are a collection of consecutive blocks on disk.
+		 *
+		 * The current MFS implementation supports only filesystems
+		 * where the size of a zone is equal to the
+		 * size of a block.
+		 */
+		rc = ENOTSUP;
+		goto out_error;
+	}
+
 	sbi->itable_off = 2 + sbi->ibmap_blocks + sbi->zbmap_blocks;
-
-	free(sb);
+	if ((rc = mfs_check_sanity(sbi)) != EOK) {
+		fprintf(stderr, "Filesystem corrupted, invalid superblock");
+		goto out_error;
+	}
 
 	rc = block_cache_init(service_id, sbi->block_size, 0, cmode);
 	if (rc != EOK) {
-		free(instance);
-		free(sbi);
-		free(sb);
-		block_cache_fini(service_id);
-		block_fini(service_id);
 		mfsdebug("block cache initialization failed\n");
-		return EINVAL;
-	}
-
-	/*Initialize the instance structure and add it to the list*/
-	link_initialize(&instance->link);
+		rc = EINVAL;
+		goto out_error;
+	}
+
+	/* Initialize the instance structure and remember it */
 	instance->service_id = service_id;
 	instance->sbi = sbi;
-
-	fibril_mutex_lock(&inst_list_mutex);
-	list_append(&instance->link, &inst_list);
-	fibril_mutex_unlock(&inst_list_mutex);
+	instance->open_nodes_cnt = 0;
+	rc = fs_instance_create(service_id, instance);
+	if (rc != EOK) {
+		block_cache_fini(service_id);
+		mfsdebug("fs instance creation failed\n");
+		goto out_error;
+	}
 
 	mfsdebug("mount successful\n");
@@ -295,5 +296,17 @@
 	*linkcnt = 1;
 
+	free(sb);
+
 	return mfs_node_put(fn);
+
+out_error:
+	block_fini(service_id);
+	if (sb)
+		free(sb);
+	if (sbi)
+		free(sbi);
+	if(instance)
+		free(instance);
+	return rc;
 }
 
@@ -315,9 +328,6 @@
 	block_fini(service_id);
 
-	/* Remove the instance from the list */
-	fibril_mutex_lock(&inst_list_mutex);
-	list_remove(&inst->link);
-	fibril_mutex_unlock(&inst_list_mutex);
-
+	/* Remove and destroy the instance */
+	(void) fs_instance_destroy(service_id);
 	free(inst->sbi);
 	free(inst);
@@ -325,5 +335,6 @@
 }
 
-service_id_t mfs_service_get(fs_node_t *fsnode)
+service_id_t
+mfs_service_get(fs_node_t *fsnode)
 {
 	struct mfs_node *node = fsnode->data;
@@ -331,5 +342,6 @@
 }
 
-static int mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
+static int
+mfs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)
 {
 	int r;
@@ -345,5 +357,5 @@
 		return r;
 
-	/*Alloc a new inode*/
+	/* Alloc a new inode */
 	r = mfs_alloc_inode(inst, &inum);
 	if (r != EOK)
@@ -372,9 +384,7 @@
 	if (flags & L_DIRECTORY) {
 		ino_i->i_mode = S_IFDIR;
-		ino_i->i_nlinks = 2; /*This accounts for the '.' dentry*/
-	} else {
+		ino_i->i_nlinks = 1; /* This accounts for the '.' dentry */
+	} else
 		ino_i->i_mode = S_IFREG;
-		ino_i->i_nlinks = 1;
-	}
 
 	ino_i->i_uid = 0;
@@ -425,5 +435,6 @@
 }
 
-static int mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
+static int
+mfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)
 {
 	struct mfs_node *mnode = pfn->data;
@@ -447,5 +458,5 @@
 
 		if (!d_info.d_inum) {
-			/*This entry is not used*/
+			/* This entry is not used */
 			continue;
 		}
@@ -454,8 +465,8 @@
 
 		if (comp_size == dentry_name_size &&
-			!bcmp(component, d_info.d_name, dentry_name_size)) {
-			/*Hit!*/
+		    !bcmp(component, d_info.d_name, dentry_name_size)) {
+			/* Hit! */
 			mfs_node_core_get(rfn, mnode->instance,
-					  d_info.d_inum);
+			    d_info.d_inum);
 			goto found;
 		}
@@ -466,5 +477,6 @@
 }
 
-static aoff64_t mfs_size_get(fs_node_t *node)
+static aoff64_t
+mfs_size_get(fs_node_t *node)
 {
 	const struct mfs_node *mnode = node->data;
@@ -474,5 +486,5 @@
 static int
 mfs_node_get(fs_node_t **rfn, service_id_t service_id,
-			fs_index_t index)
+    fs_index_t index)
 {
 	int rc;
@@ -518,5 +530,6 @@
 }
 
-static int mfs_node_open(fs_node_t *fsnode)
+static int
+mfs_node_open(fs_node_t *fsnode)
 {
 	/*
@@ -527,5 +540,6 @@
 }
 
-static fs_index_t mfs_index_get(fs_node_t *fsnode)
+static fs_index_t
+mfs_index_get(fs_node_t *fsnode)
 {
 	struct mfs_node *mnode = fsnode->data;
@@ -533,5 +547,6 @@
 }
 
-static unsigned mfs_lnkcnt_get(fs_node_t *fsnode)
+static unsigned
+mfs_lnkcnt_get(fs_node_t *fsnode)
 {
 	struct mfs_node *mnode = fsnode->data;
@@ -548,6 +563,7 @@
 }
 
-static int mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
-			     fs_index_t index)
+static int
+mfs_node_core_get(fs_node_t **rfn, struct mfs_instance *inst,
+    fs_index_t index)
 {
 	fs_node_t *node = NULL;
@@ -621,5 +637,6 @@
 }
 
-static bool mfs_is_directory(fs_node_t *fsnode)
+static bool
+mfs_is_directory(fs_node_t *fsnode)
 {
 	const struct mfs_node *node = fsnode->data;
@@ -627,5 +644,6 @@
 }
 
-static bool mfs_is_file(fs_node_t *fsnode)
+static bool
+mfs_is_file(fs_node_t *fsnode)
 {
 	struct mfs_node *node = fsnode->data;
@@ -633,5 +651,6 @@
 }
 
-static int mfs_root_get(fs_node_t **rfn, service_id_t service_id)
+static int
+mfs_root_get(fs_node_t **rfn, service_id_t service_id)
 {
 	int rc = mfs_node_get(rfn, service_id, MFS_ROOT_INO);
@@ -639,9 +658,11 @@
 }
 
-static int mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
+static int
+mfs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)
 {
 	struct mfs_node *parent = pfn->data;
 	struct mfs_node *child = cfn->data;
 	struct mfs_sb_info *sbi = parent->instance->sbi;
+	bool destroy_dentry = false;
 
 	mfsdebug("%s()\n", __FUNCTION__);
@@ -652,14 +673,24 @@
 	int r = mfs_insert_dentry(parent, name, child->ino_i->index);
 	if (r != EOK)
-		goto exit_error;
+		return r;
 
 	if (S_ISDIR(child->ino_i->i_mode)) {
+		if (child->ino_i->i_nlinks != 1) {
+			/* It's not possible to hardlink directories in MFS */
+			destroy_dentry = true;
+			r = EMLINK;
+			goto exit;
+		}
 		r = mfs_insert_dentry(child, ".", child->ino_i->index);
-		if (r != EOK)
-			goto exit_error;
+		if (r != EOK) {
+			destroy_dentry = true;
+			goto exit;
+		}
 
 		r = mfs_insert_dentry(child, "..", parent->ino_i->index);
-		if (r != EOK)
-			goto exit_error;
+		if (r != EOK) {
+			destroy_dentry = true;
+			goto exit;
+		}
 
 		parent->ino_i->i_nlinks++;
@@ -667,5 +698,13 @@
 	}
 
-exit_error:
+exit:
+	if (destroy_dentry) {
+		int r2 = mfs_remove_dentry(parent, name);
+		if (r2 != EOK)
+			r = r2;
+	} else {
+		child->ino_i->i_nlinks++;
+		child->ino_i->dirty = true;
+	}
 	return r;
 }
@@ -714,5 +753,6 @@
 }
 
-static int mfs_has_children(bool *has_children, fs_node_t *fsnode)
+static int
+mfs_has_children(bool *has_children, fs_node_t *fsnode)
 {
 	struct mfs_node *mnode = fsnode->data;
@@ -735,5 +775,5 @@
 
 		if (d_info.d_inum) {
-			/*A valid entry has been found*/
+			/* A valid entry has been found */
 			*has_children = true;
 			break;
@@ -747,5 +787,5 @@
 static int
 mfs_read(service_id_t service_id, fs_index_t index, aoff64_t pos,
-		size_t *rbytes)
+    size_t *rbytes)
 {
 	int rc;
@@ -777,5 +817,5 @@
 
 		if (pos < 2) {
-			/*Skip the first two dentries ('.' and '..')*/
+			/* Skip the first two dentries ('.' and '..') */
 			pos = 2;
 		}
@@ -787,5 +827,5 @@
 
 			if (d_info.d_inum) {
-				/*Dentry found!*/
+				/* Dentry found! */
 				goto found;
 			}
@@ -797,5 +837,5 @@
 found:
 		async_data_read_finalize(callid, d_info.d_name,
-					 str_size(d_info.d_name) + 1);
+		    str_size(d_info.d_name) + 1);
 		bytes = ((pos - spos) + 1);
 	} else {
@@ -803,5 +843,5 @@
 
 		if (pos >= (size_t) ino_i->i_size) {
-			/*Trying to read beyond the end of file*/
+			/* Trying to read beyond the end of file */
 			bytes = 0;
 			(void) async_data_read_finalize(callid, NULL, 0);
@@ -820,5 +860,5 @@
 
 		if (zone == 0) {
-			/*sparse file*/
+			/* sparse file */
 			uint8_t *buf = malloc(sbi->block_size);
 			if (!buf) {
@@ -828,5 +868,5 @@
 			memset(buf, 0, sizeof(sbi->block_size));
 			async_data_read_finalize(callid,
-						 buf + pos % sbi->block_size, bytes);
+			    buf + pos % sbi->block_size, bytes);
 			free(buf);
 			goto out_success;
@@ -838,5 +878,5 @@
 
 		async_data_read_finalize(callid, b->data +
-					 pos % sbi->block_size, bytes);
+		    pos % sbi->block_size, bytes);
 
 		rc = block_put(b);
@@ -859,5 +899,5 @@
 static int
 mfs_write(service_id_t service_id, fs_index_t index, aoff64_t pos,
-		size_t *wbytes, aoff64_t *nsize)
+    size_t *wbytes, aoff64_t *nsize)
 {
 	fs_node_t *fn;
@@ -883,6 +923,5 @@
 	struct mfs_ino_info *ino_i = mnode->ino_i;
 	const size_t bs = sbi->block_size;
-	size_t bytes = min(len, bs - pos % bs);
-	size_t boundary = ROUND_UP(ino_i->i_size, bs);
+	size_t bytes = min(len, bs - (pos % bs));
 	uint32_t block;
 
@@ -890,17 +929,9 @@
 		flags = BLOCK_FLAGS_NOREAD;
 
-	if (pos < boundary) {
-		r = mfs_read_map(&block, mnode, pos);
-		if (r != EOK)
-			goto out_err;
-
-		if (block == 0) {
-			/*Writing in a sparse block*/
-			r = mfs_alloc_zone(mnode->instance, &block);
-			if (r != EOK)
-				goto out_err;
-			flags = BLOCK_FLAGS_NOREAD;
-		}
-	} else {
+	r = mfs_read_map(&block, mnode, pos);
+	if (r != EOK)
+		goto out_err;
+
+	if (block == 0) {
 		uint32_t dummy;
 
@@ -908,8 +939,10 @@
 		if (r != EOK)
 			goto out_err;
-
+		
 		r = mfs_write_map(mnode, pos, block, &dummy);
 		if (r != EOK)
 			goto out_err;
+
+		flags = BLOCK_FLAGS_NOREAD;
 	}
 
@@ -919,5 +952,8 @@
 		goto out_err;
 
-	async_data_write_finalize(callid, b->data + pos % bs, bytes);
+	if (flags == BLOCK_FLAGS_NOREAD)
+		memset(b->data, 0, sbi->block_size);
+
+	async_data_write_finalize(callid, b->data + (pos % bs), bytes);
 	b->dirty = true;
 
@@ -928,8 +964,10 @@
 	}
 
-	ino_i->i_size = pos + bytes;
-	ino_i->dirty = true;
+	if (pos + bytes > ino_i->i_size) {
+		ino_i->i_size = pos + bytes;
+		ino_i->dirty = true;
+	}
 	r = mfs_node_put(fn);
-	*nsize = pos + bytes;
+	*nsize = ino_i->i_size;
 	*wbytes = bytes;
 	return r;
@@ -953,5 +991,5 @@
 		return ENOENT;
 
-	/*Destroy the inode*/
+	/* Destroy the inode */
 	return mfs_destroy_node(fn);
 }
@@ -972,10 +1010,10 @@
 	assert(!has_children);
 
-	/*Free the entire inode content*/
+	/* Free the entire inode content */
 	r = mfs_inode_shrink(mnode, mnode->ino_i->i_size);
 	if (r != EOK)
 		goto out;
 
-	/*Mark the inode as free in the bitmap*/
+	/* Mark the inode as free in the bitmap */
 	r = mfs_free_inode(mnode->instance, mnode->ino_i->index);
 
@@ -1012,32 +1050,20 @@
 mfs_instance_get(service_id_t service_id, struct mfs_instance **instance)
 {
-	struct mfs_instance *instance_ptr;
-
-	fibril_mutex_lock(&inst_list_mutex);
-
-	if (list_empty(&inst_list)) {
-		fibril_mutex_unlock(&inst_list_mutex);
-		return EINVAL;
-	}
-
-	list_foreach(inst_list, link) {
-		instance_ptr = list_get_instance(link, struct mfs_instance,
-						 link);
-
-		if (instance_ptr->service_id == service_id) {
-			*instance = instance_ptr;
-			fibril_mutex_unlock(&inst_list_mutex);
-			return EOK;
-		}
-	}
-
-	mfsdebug("Instance not found\n");
-
-	fibril_mutex_unlock(&inst_list_mutex);
-	return EINVAL;
-}
-
-static bool check_magic_number(uint16_t magic, bool *native,
-			       mfs_version_t *version, bool *longfilenames)
+	void *data;
+	int rc;
+
+	rc = fs_instance_get(service_id, &data);
+	if (rc == EOK)
+		*instance = (struct mfs_instance *) data;
+	else {
+		mfsdebug("instance not found\n");
+	}
+
+	return rc;
+}
+
+static bool
+check_magic_number(uint16_t magic, bool *native,
+		mfs_version_t *version, bool *longfilenames)
 {
 	bool rc = true;
@@ -1067,4 +1093,27 @@
 }
 
+/** Filesystem sanity check
+ *
+ * @param Pointer to the MFS superblock.
+ *
+ * @return EOK on success, ENOTSUP otherwise.
+ */
+static int
+mfs_check_sanity(struct mfs_sb_info *sbi)
+{
+	if (!is_power_of_two(sbi->block_size) ||
+	    sbi->block_size < MFS_MIN_BLOCKSIZE ||
+	    sbi->block_size > MFS_MAX_BLOCKSIZE)
+		return ENOTSUP;
+	else if (sbi->ibmap_blocks == 0 || sbi->zbmap_blocks == 0)
+		return ENOTSUP;
+	else if (sbi->ninodes == 0 || sbi->nzones == 0)
+		return ENOTSUP;
+	else if (sbi->firstdatazone == 0)
+		return ENOTSUP;
+
+	return EOK;
+}
+
 static int
 mfs_close(service_id_t service_id, fs_index_t index)
@@ -1087,4 +1136,19 @@
 
 	return mfs_node_put(fn);
+}
+
+/** Check if a given number is a power of two.
+ *
+ * @param n	The number to check.
+ *
+ * @return	true if it is a power of two, false otherwise.
+ */
+static bool
+is_power_of_two(uint32_t n)
+{
+	if (n == 0)
+		return false;
+
+	return (n & (n - 1)) == 0;
 }
 
Index: uspace/srv/fs/mfs/mfs_rw.c
===================================================================
--- uspace/srv/fs/mfs/mfs_rw.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/mfs/mfs_rw.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -31,9 +31,10 @@
  */
 
+#include <align.h>
 #include "mfs.h"
 
 static int
 rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
-	      bool write_mode, uint32_t w_block);
+    bool write_mode, uint32_t w_block);
 
 static int
@@ -67,9 +68,9 @@
 	const int block_size = sbi->block_size;
 
-	/*Compute relative block number in file*/
+	/* Compute relative block number in file */
 	int rblock = pos / block_size;
 
-	if (mnode->ino_i->i_size < pos) {
-		/*Trying to read beyond the end of file*/
+	if (ROUND_UP(mnode->ino_i->i_size, sbi->block_size) < pos) {
+		/* Trying to read beyond the end of file */
 		r = EOK;
 		*b = 0;
@@ -84,14 +85,14 @@
 int
 mfs_write_map(struct mfs_node *mnode, const uint32_t pos, uint32_t new_zone,
-	  uint32_t *old_zone)
+    uint32_t *old_zone)
 {
 	const struct mfs_sb_info *sbi = mnode->instance->sbi;
 
 	if (pos >= sbi->max_file_size) {
-		/*Can't write beyond the maximum file size*/
+		/* Can't write beyond the maximum file size */
 		return EINVAL;
 	}
 
-	/*Compute the relative block number in file*/
+	/* Compute the relative block number in file */
 	int rblock = pos / sbi->block_size;
 
@@ -101,5 +102,5 @@
 static int
 rw_map_ondisk(uint32_t *b, const struct mfs_node *mnode, int rblock,
-	      bool write_mode, uint32_t w_block)
+    bool write_mode, uint32_t w_block)
 {
 	int r, nr_direct;
@@ -122,5 +123,5 @@
 	}
 
-	/*Check if the wanted block is in the direct zones*/
+	/* Check if the wanted block is in the direct zones */
 	if (rblock < nr_direct) {
 		*b = ino_i->i_dzone[rblock];
@@ -135,5 +136,5 @@
 
 	if (rblock < ptrs_per_block) {
-		/*The wanted block is in the single indirect zone chain*/
+		/* The wanted block is in the single indirect zone chain */
 		if (ino_i->i_izone[0] == 0) {
 			if (write_mode && !deleting) {
@@ -146,5 +147,5 @@
 				ino_i->dirty = true;
 			} else {
-				/*Sparse block*/
+				/* Sparse block */
 				*b = 0;
 				return EOK;
@@ -167,7 +168,7 @@
 	rblock -= ptrs_per_block;
 
-	/*The wanted block is in the double indirect zone chain*/
-
-	/*read the first indirect zone of the chain*/
+	/* The wanted block is in the double indirect zone chain */
+
+	/* Read the first indirect zone of the chain */
 	if (ino_i->i_izone[1] == 0) {
 		if (write_mode && !deleting) {
@@ -180,5 +181,5 @@
 			ino_i->dirty = true;
 		} else {
-			/*Sparse block*/
+			/* Sparse block */
 			*b = 0;
 			return EOK;
@@ -191,10 +192,10 @@
 
 	/*
-	 *Compute the position of the second indirect
-	 *zone pointer in the chain.
+	 * Compute the position of the second indirect
+	 * zone pointer in the chain.
 	 */
 	uint32_t ind2_off = rblock / ptrs_per_block;
 
-	/*read the second indirect zone of the chain*/
+	/* read the second indirect zone of the chain */
 	if (ind_zone[ind2_off] == 0) {
 		if (write_mode && !deleting) {
@@ -207,5 +208,5 @@
 			write_ind_zone(inst, ino_i->i_izone[1], ind_zone);
 		} else {
-			/*Sparse block*/
+			/* Sparse block */
 			r = EOK;
 			*b = 0;
@@ -232,5 +233,5 @@
 }
 
-/**Free unused indirect zones from a MINIX inode according to it's new size.
+/**Free unused indirect zones from a MINIX inode according to its new size.
  *
  * @param mnode		Pointer to a generic MINIX inode in memory.
@@ -263,5 +264,5 @@
 
 	if (rblock < nr_direct) {
-		/*free the single indirect zone*/
+		/* Free the single indirect zone */
 		if (ino_i->i_izone[0]) {
 			r = mfs_free_zone(inst, ino_i->i_izone[0]);
@@ -281,9 +282,9 @@
 		++fzone_to_free;
 
-	/*free the entire double indirect zone*/
+	/* Free the entire double indirect zone */
 	uint32_t *dbl_zone;
 
 	if (ino_i->i_izone[1] == 0) {
-		/*Nothing to be done*/
+		/* Nothing to be done */
 		return EOK;
 	}
@@ -349,5 +350,5 @@
 	block_t *b;
 	const int max_ind_zone_ptrs = (MFS_MAX_BLOCKSIZE / sizeof(uint16_t)) *
-				      sizeof(uint32_t);
+	    sizeof(uint32_t);
 
 	*ind_zone = malloc(max_ind_zone_ptrs);
Index: uspace/srv/fs/mfs/mfs_utils.c
===================================================================
--- uspace/srv/fs/mfs/mfs_utils.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/mfs/mfs_utils.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -34,5 +34,6 @@
 #include "mfs.h"
 
-uint16_t conv16(bool native, uint16_t n)
+uint16_t
+conv16(bool native, uint16_t n)
 {
 	if (native)
@@ -42,5 +43,6 @@
 }
 
-uint32_t conv32(bool native, uint32_t n)
+uint32_t
+conv32(bool native, uint32_t n)
 {
 	if (native)
@@ -50,5 +52,6 @@
 }
 
-uint64_t conv64(bool native, uint64_t n)
+uint64_t
+conv64(bool native, uint64_t n)
 {
 	if (native)
Index: uspace/srv/fs/tmpfs/tmpfs.c
===================================================================
--- uspace/srv/fs/tmpfs/tmpfs.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/fs/tmpfs/tmpfs.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -59,4 +59,5 @@
 	.concurrent_read_write = false,
 	.write_retains_size = false,
+	.instance = 0,
 };
 
@@ -64,4 +65,13 @@
 {
 	printf(NAME ": HelenOS TMPFS file system server\n");
+
+	if (argc == 3) {
+		if (!str_cmp(argv[1], "--instance"))
+			tmpfs_vfs_info.instance = strtol(argv[2], NULL, 10);
+		else {
+			printf(NAME " Unrecognized parameters");
+			return -1;
+		}
+	}
 	
 	if (!tmpfs_init()) {
Index: uspace/srv/hid/console/console.c
===================================================================
--- uspace/srv/hid/console/console.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/hid/console/console.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -344,4 +344,19 @@
 }
 
+static console_t *cons_get_active_uspace(void)
+{
+	fibril_mutex_lock(&switch_mtx);
+
+	console_t *active_uspace = active_console;
+	if (active_uspace == kernel_console) {
+		active_uspace = prev_console;
+	}
+	assert(active_uspace != kernel_console);
+
+	fibril_mutex_unlock(&switch_mtx);
+
+	return active_uspace;
+}
+
 static ssize_t limit(ssize_t val, ssize_t lo, ssize_t hi)
 {
@@ -466,5 +481,14 @@
 				event->c = c;
 				
-				prodcons_produce(&active_console->input_pc, &event->link);
+				/*
+				 * Kernel console does not read events
+				 * from us, so we will redirect them
+				 * to the (last) active userspace console
+				 * if necessary.
+				 */
+				console_t *target_console = cons_get_active_uspace();
+				
+				prodcons_produce(&target_console->input_pc,
+				    &event->link);
 			}
 			
@@ -904,4 +928,5 @@
 		atomic_set(&consoles[i].refcnt, 0);
 		fibril_mutex_initialize(&consoles[i].mtx);
+		prodcons_initialize(&consoles[i].input_pc);
 		
 		if (graphics_state == GRAPHICS_FULL) {
@@ -942,5 +967,4 @@
 		}
 		
-		prodcons_initialize(&consoles[i].input_pc);
 		cons_redraw_state(&consoles[i]);
 		
Index: uspace/srv/hid/input/ctl/kbdev.c
===================================================================
--- uspace/srv/hid/input/ctl/kbdev.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/hid/input/ctl/kbdev.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -111,4 +111,5 @@
 		printf("%s: Failed allocating device structure for '%s'.\n",
 		    NAME, kdev->svc_name);
+		async_hangup(sess);
 		return -1;
 	}
@@ -169,5 +170,5 @@
 		callid = async_get_call(&call);
 		if (!IPC_GET_IMETHOD(call)) {
-			/* XXX Handle hangup */
+			kbdev_destroy(kbdev);
 			return;
 		}
Index: uspace/srv/hid/input/proto/mousedev.c
===================================================================
--- uspace/srv/hid/input/proto/mousedev.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/hid/input/proto/mousedev.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -54,7 +54,4 @@
 	/** Link to generic mouse device */
 	mouse_dev_t *mouse_dev;
-	
-	/** Session to mouse device */
-	async_sess_t *sess;
 } mousedev_t;
 
@@ -72,7 +69,4 @@
 static void mousedev_destroy(mousedev_t *mousedev)
 {
-	if (mousedev->sess != NULL)
-		async_hangup(mousedev->sess);
-	
 	free(mousedev);
 }
@@ -89,5 +83,5 @@
 		
 		if (!IPC_GET_IMETHOD(call)) {
-			/* XXX Handle hangup */
+			mousedev_destroy(mousedev);
 			return;
 		}
@@ -129,8 +123,7 @@
 		printf("%s: Failed allocating device structure for '%s'.\n",
 		    NAME, mdev->svc_name);
+		async_hangup(sess);
 		return -1;
 	}
-	
-	mousedev->sess = sess;
 	
 	async_exch_t *exch = async_exchange_begin(sess);
@@ -139,4 +132,5 @@
 		    mdev->svc_name);
 		mousedev_destroy(mousedev);
+		async_hangup(sess);
 		return -1;
 	}
@@ -144,4 +138,5 @@
 	int rc = async_connect_to_me(exch, 0, 0, 0, mousedev_callback_conn, mousedev);
 	async_exchange_end(exch);
+	async_hangup(sess);
 	
 	if (rc != EOK) {
Index: uspace/srv/hw/irc/apic/apic.c
===================================================================
--- uspace/srv/hw/irc/apic/apic.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/hw/irc/apic/apic.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -133,4 +133,6 @@
 	// FIXME: get the map from the kernel, even though this may work
 	//	  for simple cases
+	if (irq == 0)
+		return 2;
 	return irq;
 }
@@ -206,7 +208,10 @@
 	}
 
-	if (pio_enable((void *) IO_APIC_BASE, IO_APIC_SIZE,
-	    (void **) &io_apic) != EOK)
+	int rc = pio_enable((void *) IO_APIC_BASE, IO_APIC_SIZE,
+		(void **) &io_apic);
+	if (rc != EOK) {
+		printf("%s: Failed to enable PIO for APIC: %d\n", NAME, rc);
 		return false;	
+	}
 	
 	async_set_client_connection(apic_connection);
Index: uspace/srv/hw/netif/ne2000/Makefile
===================================================================
--- uspace/srv/hw/netif/ne2000/Makefile	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,47 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-USPACE_PREFIX = ../../../..
-ROOT_PATH = $(USPACE_PREFIX)/..
-LIBS = $(LIBNET_PREFIX)/libnet.a
-EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
-
-COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
-CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
-
--include $(COMMON_MAKEFILE)
--include $(CONFIG_MAKEFILE)
-
-BINARY = ne2000
-
-SOURCES = \
-	dp8390.c \
-	ne2000.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/hw/netif/ne2000/dp8390.c
===================================================================
--- uspace/srv/hw/netif/ne2000/dp8390.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,656 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This code is based upon the NE2000 driver for MINIX,
- * distributed according to a BSD-style license.
- *
- * Copyright (c) 1987, 1997, 2006 Vrije Universiteit
- * Copyright (c) 1992, 1994 Philip Homburg
- * Copyright (c) 1996 G. Falzoni
- *
- */
-
-/** @addtogroup ne2000
- *  @{
- */
-
-/** @file
- *
- * NE2000 (based on DP8390) network interface core implementation.
- * Only the basic NE2000 PIO (ISA) interface is supported, remote
- * DMA is completely absent from this code for simplicity.
- *
- */
-
-#include <assert.h>
-#include <byteorder.h>
-#include <errno.h>
-#include <stdio.h>
-#include <libarch/ddi.h>
-#include <net/packet.h>
-#include <packet_client.h>
-#include "dp8390.h"
-
-/** Page size */
-#define DP_PAGE  256
-
-/** 6 * DP_PAGE >= 1514 bytes */
-#define SQ_PAGES  6
-
-/* NE2000 implementation. */
-
-/** NE2000 Data Register */
-#define NE2K_DATA  0x0010
-
-/** NE2000 Reset register */
-#define NE2K_RESET  0x001f
-
-/** NE2000 data start */
-#define NE2K_START  0x4000
-
-/** NE2000 data size */
-#define NE2K_SIZE  0x4000
-
-/** NE2000 retry count */
-#define NE2K_RETRY  0x1000
-
-/** NE2000 error messages rate limiting */
-#define NE2K_ERL  10
-
-/** Minimum Ethernet packet size in bytes */
-#define ETH_MIN_PACK_SIZE  60
-
-/** Maximum Ethernet packet size in bytes */
-#define ETH_MAX_PACK_SIZE_TAGGED  1518
-
-/** Type definition of the receive header
- *
- */
-typedef struct {
-	/** Copy of RSR */
-	uint8_t status;
-	
-	/** Pointer to next packet */
-	uint8_t next;
-	
-	/** Receive Byte Count Low */
-	uint8_t rbcl;
-	
-	/** Receive Byte Count High */
-	uint8_t rbch;
-} recv_header_t;
-
-/** Read a memory block word by word.
- *
- * @param[in]  port Source address.
- * @param[out] buf  Destination buffer.
- * @param[in]  size Memory block size in bytes.
- *
- */
-static void pio_read_buf_16(void *port, void *buf, size_t size)
-{
-	size_t i;
-	
-	for (i = 0; (i << 1) < size; i++)
-		*((uint16_t *) buf + i) = pio_read_16((ioport16_t *) (port));
-}
-
-/** Write a memory block word by word.
- *
- * @param[in] port Destination address.
- * @param[in] buf  Source buffer.
- * @param[in] size Memory block size in bytes.
- *
- */
-static void pio_write_buf_16(void *port, void *buf, size_t size)
-{
-	size_t i;
-	
-	for (i = 0; (i << 1) < size; i++)
-		pio_write_16((ioport16_t *) port, *((uint16_t *) buf + i));
-}
-
-static void ne2k_download(ne2k_t *ne2k, void *buf, size_t addr, size_t size)
-{
-	size_t esize = size & ~1;
-	
-	pio_write_8(ne2k->port + DP_RBCR0, esize & 0xff);
-	pio_write_8(ne2k->port + DP_RBCR1, (esize >> 8) & 0xff);
-	pio_write_8(ne2k->port + DP_RSAR0, addr & 0xff);
-	pio_write_8(ne2k->port + DP_RSAR1, (addr >> 8) & 0xff);
-	pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-	
-	if (esize != 0) {
-		pio_read_buf_16(ne2k->data_port, buf, esize);
-		size -= esize;
-		buf += esize;
-	}
-	
-	if (size) {
-		assert(size == 1);
-		
-		uint16_t word = pio_read_16(ne2k->data_port);
-		memcpy(buf, &word, 1);
-	}
-}
-
-static void ne2k_upload(ne2k_t *ne2k, void *buf, size_t addr, size_t size)
-{
-	size_t esize_ru = (size + 1) & ~1;
-	size_t esize = size & ~1;
-	
-	pio_write_8(ne2k->port + DP_RBCR0, esize_ru & 0xff);
-	pio_write_8(ne2k->port + DP_RBCR1, (esize_ru >> 8) & 0xff);
-	pio_write_8(ne2k->port + DP_RSAR0, addr & 0xff);
-	pio_write_8(ne2k->port + DP_RSAR1, (addr >> 8) & 0xff);
-	pio_write_8(ne2k->port + DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
-	
-	if (esize != 0) {
-		pio_write_buf_16(ne2k->data_port, buf, esize);
-		size -= esize;
-		buf += esize;
-	}
-	
-	if (size) {
-		assert(size == 1);
-		
-		uint16_t word = 0;
-		
-		memcpy(&word, buf, 1);
-		pio_write_16(ne2k->data_port, word);
-	}
-}
-
-static void ne2k_init(ne2k_t *ne2k)
-{
-	unsigned int i;
-	
-	/* Reset the ethernet card */
-	uint8_t val = pio_read_8(ne2k->port + NE2K_RESET);
-	usleep(2000);
-	pio_write_8(ne2k->port + NE2K_RESET, val);
-	usleep(2000);
-	
-	/* Reset the DP8390 */
-	pio_write_8(ne2k->port + DP_CR, CR_STP | CR_DM_ABORT);
-	for (i = 0; i < NE2K_RETRY; i++) {
-		if (pio_read_8(ne2k->port + DP_ISR) != 0)
-			break;
-	}
-}
-
-/** Probe and initialize the network interface.
- *
- * @param[in,out] ne2k Network interface structure.
- * @param[in]     port Device address.
- * @param[in]     irq  Device interrupt vector.
- *
- * @return EOK on success.
- * @return EXDEV if the network interface was not recognized.
- *
- */
-int ne2k_probe(ne2k_t *ne2k, void *port, int irq)
-{
-	unsigned int i;
-	
-	/* General initialization */
-	ne2k->port = port;
-	ne2k->data_port = ne2k->port + NE2K_DATA;
-	ne2k->irq = irq;
-	ne2k->probed = false;
-	ne2k->up = false;
-	
-	ne2k_init(ne2k);
-	
-	/* Check if the DP8390 is really there */
-	uint8_t val = pio_read_8(ne2k->port + DP_CR);
-	if ((val & (CR_STP | CR_DM_ABORT)) != (CR_STP | CR_DM_ABORT))
-		return EXDEV;
-	
-	/* Disable the receiver and init TCR and DCR */
-	pio_write_8(ne2k->port + DP_RCR, RCR_MON);
-	pio_write_8(ne2k->port + DP_TCR, TCR_NORMAL);
-	pio_write_8(ne2k->port + DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
-	
-	/* Setup a transfer to get the MAC address */
-	pio_write_8(ne2k->port + DP_RBCR0, ETH_ADDR << 1);
-	pio_write_8(ne2k->port + DP_RBCR1, 0);
-	pio_write_8(ne2k->port + DP_RSAR0, 0);
-	pio_write_8(ne2k->port + DP_RSAR1, 0);
-	pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-	
-	for (i = 0; i < ETH_ADDR; i++)
-		ne2k->mac[i] = pio_read_16(ne2k->data_port);
-	
-	ne2k->probed = true;
-	return EOK;
-}
-
-/** Start the network interface.
- *
- * @param[in,out] ne2k Network interface structure.
- *
- * @return EOK on success.
- * @return EXDEV if the network interface is disabled.
- *
- */
-int ne2k_up(ne2k_t *ne2k)
-{
-	if (!ne2k->probed)
-		return EXDEV;
-	
-	ne2k_init(ne2k);
-	
-	/*
-	 * Setup send queue. Use the first
-	 * SQ_PAGES of NE2000 memory for the send
-	 * buffer.
-	 */
-	ne2k->sq.dirty = false;
-	ne2k->sq.page = NE2K_START / DP_PAGE;
-	fibril_mutex_initialize(&ne2k->sq_mutex);
-	fibril_condvar_initialize(&ne2k->sq_cv);
-	
-	/*
-	 * Setup receive ring buffer. Use all the rest
-	 * of the NE2000 memory (except the first SQ_PAGES
-	 * reserved for the send buffer) for the receive
-	 * ring buffer.
-	 */
-	ne2k->start_page = ne2k->sq.page + SQ_PAGES;
-	ne2k->stop_page = ne2k->sq.page + NE2K_SIZE / DP_PAGE;
-	
-	/*
-	 * Initialization of the DP8390 following the mandatory procedure
-	 * in reference manual ("DP8390D/NS32490D NIC Network Interface
-	 * Controller", National Semiconductor, July 1995, Page 29).
-	 */
-	
-	/* Step 1: */
-	pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT);
-	
-	/* Step 2: */
-	pio_write_8(ne2k->port + DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
-	
-	/* Step 3: */
-	pio_write_8(ne2k->port + DP_RBCR0, 0);
-	pio_write_8(ne2k->port + DP_RBCR1, 0);
-	
-	/* Step 4: */
-	pio_write_8(ne2k->port + DP_RCR, RCR_AB);
-	
-	/* Step 5: */
-	pio_write_8(ne2k->port + DP_TCR, TCR_INTERNAL);
-	
-	/* Step 6: */
-	pio_write_8(ne2k->port + DP_BNRY, ne2k->start_page);
-	pio_write_8(ne2k->port + DP_PSTART, ne2k->start_page);
-	pio_write_8(ne2k->port + DP_PSTOP, ne2k->stop_page);
-	
-	/* Step 7: */
-	pio_write_8(ne2k->port + DP_ISR, 0xff);
-	
-	/* Step 8: */
-	pio_write_8(ne2k->port + DP_IMR,
-	    IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE | IMR_OVWE | IMR_CNTE);
-	
-	/* Step 9: */
-	pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
-	
-	pio_write_8(ne2k->port + DP_PAR0, ne2k->mac[0]);
-	pio_write_8(ne2k->port + DP_PAR1, ne2k->mac[1]);
-	pio_write_8(ne2k->port + DP_PAR2, ne2k->mac[2]);
-	pio_write_8(ne2k->port + DP_PAR3, ne2k->mac[3]);
-	pio_write_8(ne2k->port + DP_PAR4, ne2k->mac[4]);
-	pio_write_8(ne2k->port + DP_PAR5, ne2k->mac[5]);
-	
-	pio_write_8(ne2k->port + DP_MAR0, 0xff);
-	pio_write_8(ne2k->port + DP_MAR1, 0xff);
-	pio_write_8(ne2k->port + DP_MAR2, 0xff);
-	pio_write_8(ne2k->port + DP_MAR3, 0xff);
-	pio_write_8(ne2k->port + DP_MAR4, 0xff);
-	pio_write_8(ne2k->port + DP_MAR5, 0xff);
-	pio_write_8(ne2k->port + DP_MAR6, 0xff);
-	pio_write_8(ne2k->port + DP_MAR7, 0xff);
-	
-	pio_write_8(ne2k->port + DP_CURR, ne2k->start_page + 1);
-	
-	/* Step 10: */
-	pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_DM_ABORT | CR_STA);
-	
-	/* Step 11: */
-	pio_write_8(ne2k->port + DP_TCR, TCR_NORMAL);
-	
-	/* Reset counters by reading */
-	pio_read_8(ne2k->port + DP_CNTR0);
-	pio_read_8(ne2k->port + DP_CNTR1);
-	pio_read_8(ne2k->port + DP_CNTR2);
-	
-	/* Finish the initialization */
-	ne2k->up = true;
-	return EOK;
-}
-
-/** Stop the network interface.
- *
- * @param[in,out] ne2k Network interface structure.
- *
- */
-void ne2k_down(ne2k_t *ne2k)
-{
-	if ((ne2k->probed) && (ne2k->up)) {
-		pio_write_8(ne2k->port + DP_CR, CR_STP | CR_DM_ABORT);
-		ne2k_init(ne2k);
-		ne2k->up = false;
-	}
-}
-
-/** Send a frame.
- *
- * @param[in,out] ne2k   Network interface structure.
- * @param[in]     packet Frame to be sent.
- *
- */
-void ne2k_send(ne2k_t *ne2k, packet_t *packet)
-{
-	assert(ne2k->probed);
-	assert(ne2k->up);
-	
-	fibril_mutex_lock(&ne2k->sq_mutex);
-	
-	while (ne2k->sq.dirty)
-		fibril_condvar_wait(&ne2k->sq_cv, &ne2k->sq_mutex);
-	
-	void *buf = packet_get_data(packet);
-	size_t size = packet_get_data_length(packet);
-	
-	if ((size < ETH_MIN_PACK_SIZE) || (size > ETH_MAX_PACK_SIZE_TAGGED)) {
-		fibril_mutex_unlock(&ne2k->sq_mutex);
-		fprintf(stderr, "%s: Frame dropped (invalid size %zu bytes)\n",
-		    NAME, size);
-		return;
-	}
-	
-	/* Upload the frame to the ethernet card */
-	ne2k_upload(ne2k, buf, ne2k->sq.page * DP_PAGE, size);
-	ne2k->sq.dirty = true;
-	ne2k->sq.size = size;
-	
-	/* Initialize the transfer */
-	pio_write_8(ne2k->port + DP_TPSR, ne2k->sq.page);
-	pio_write_8(ne2k->port + DP_TBCR0, size & 0xff);
-	pio_write_8(ne2k->port + DP_TBCR1, (size >> 8) & 0xff);
-	pio_write_8(ne2k->port + DP_CR, CR_TXP | CR_STA);
-	
-	fibril_mutex_unlock(&ne2k->sq_mutex);
-}
-
-static void ne2k_reset(ne2k_t *ne2k)
-{
-	unsigned int i;
-	
-	/* Stop the chip */
-	pio_write_8(ne2k->port + DP_CR, CR_STP | CR_DM_ABORT);
-	pio_write_8(ne2k->port + DP_RBCR0, 0);
-	pio_write_8(ne2k->port + DP_RBCR1, 0);
-	
-	for (i = 0; i < NE2K_RETRY; i++) {
-		if ((pio_read_8(ne2k->port + DP_ISR) & ISR_RST) != 0)
-			break;
-	}
-	
-	pio_write_8(ne2k->port + DP_TCR, TCR_1EXTERNAL | TCR_OFST);
-	pio_write_8(ne2k->port + DP_CR, CR_STA | CR_DM_ABORT);
-	pio_write_8(ne2k->port + DP_TCR, TCR_NORMAL);
-	
-	/* Acknowledge the ISR_RDC (remote DMA) interrupt */
-	for (i = 0; i < NE2K_RETRY; i++) {
-		if ((pio_read_8(ne2k->port + DP_ISR) & ISR_RDC) != 0)
-			break;
-	}
-	
-	uint8_t val = pio_read_8(ne2k->port + DP_ISR);
-	pio_write_8(ne2k->port + DP_ISR, val & ~ISR_RDC);
-	
-	/*
-	 * Reset the transmit ring. If we were transmitting a frame,
-	 * we pretend that the packet is processed. Higher layers will
-	 * retransmit if the packet wasn't actually sent.
-	 */
-	fibril_mutex_lock(&ne2k->sq_mutex);
-	ne2k->sq.dirty = false;
-	fibril_mutex_unlock(&ne2k->sq_mutex);
-}
-
-static frame_t *ne2k_receive_frame(ne2k_t *ne2k, uint8_t page, size_t length)
-{
-	frame_t *frame = (frame_t *) malloc(sizeof(frame_t));
-	if (frame == NULL)
-		return NULL;
-	
-	link_initialize(&frame->link);
-	
-	frame->packet = netif_packet_get_1(length);
-	if (frame->packet == NULL) {
-		free(frame);
-		return NULL;
-	}
-	
-	void *buf = packet_suffix(frame->packet, length);
-	bzero(buf, length);
-	uint8_t last = page + length / DP_PAGE;
-	
-	if (last >= ne2k->stop_page) {
-		size_t left = (ne2k->stop_page - page) * DP_PAGE
-		    - sizeof(recv_header_t);
-		
-		ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),
-		    left);
-		ne2k_download(ne2k, buf + left, ne2k->start_page * DP_PAGE,
-		    length - left);
-	} else
-		ne2k_download(ne2k, buf, page * DP_PAGE + sizeof(recv_header_t),
-		    length);
-	
-	ne2k->stats.receive_packets++;
-	return frame;
-}
-
-static list_t *ne2k_receive(ne2k_t *ne2k)
-{
-	/*
-	 * Allocate memory for the list of received frames.
-	 * If the allocation fails here we still receive the
-	 * frames from the network, but they will be lost.
-	 */
-	list_t *frames = (list_t *) malloc(sizeof(list_t));
-	if (frames != NULL)
-		list_initialize(frames);
-	
-	while (true) {
-		uint8_t boundary = pio_read_8(ne2k->port + DP_BNRY) + 1;
-		
-		if (boundary == ne2k->stop_page)
-			boundary = ne2k->start_page;
-		
-		pio_write_8(ne2k->port + DP_CR, CR_PS_P1 | CR_STA);
-		uint8_t current = pio_read_8(ne2k->port + DP_CURR);
-		pio_write_8(ne2k->port + DP_CR, CR_PS_P0 | CR_STA);
-		
-		if (current == boundary)
-			/* No more frames to process */
-			break;
-		
-		recv_header_t header;
-		size_t size = sizeof(header);
-		size_t offset = boundary * DP_PAGE;
-		
-		/* Get the frame header */
-		pio_write_8(ne2k->port + DP_RBCR0, size & 0xff);
-		pio_write_8(ne2k->port + DP_RBCR1, (size >> 8) & 0xff);
-		pio_write_8(ne2k->port + DP_RSAR0, offset & 0xff);
-		pio_write_8(ne2k->port + DP_RSAR1, (offset >> 8) & 0xff);
-		pio_write_8(ne2k->port + DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
-		
-		pio_read_buf_16(ne2k->data_port, (void *) &header, size);
-		
-		size_t length =
-		    (((size_t) header.rbcl) | (((size_t) header.rbch) << 8)) - size;
-		uint8_t next = header.next;
-		
-		if ((length < ETH_MIN_PACK_SIZE)
-		    || (length > ETH_MAX_PACK_SIZE_TAGGED)) {
-			fprintf(stderr, "%s: Rant frame (%zu bytes)\n", NAME, length);
-			next = current;
-		} else if ((header.next < ne2k->start_page)
-		    || (header.next > ne2k->stop_page)) {
-			fprintf(stderr, "%s: Malformed next frame %u\n", NAME,
-			    header.next);
-			next = current;
-		} else if (header.status & RSR_FO) {
-			/*
-			 * This is very serious, so we issue a warning and
-			 * reset the buffers.
-			 */
-			fprintf(stderr, "%s: FIFO overrun\n", NAME);
-			ne2k->overruns++;
-			next = current;
-		} else if ((header.status & RSR_PRX) && (ne2k->up)) {
-			if (frames != NULL) {
-				frame_t *frame = ne2k_receive_frame(ne2k, boundary, length);
-				if (frame != NULL)
-					list_append(&frame->link, frames);
-			}
-		}
-		
-		/*
-		 * Update the boundary pointer
-		 * to the value of the page
-		 * prior to the next packet to
-		 * be processed.
-		 */
-		if (next == ne2k->start_page)
-			next = ne2k->stop_page - 1;
-		else
-			next--;
-		
-		pio_write_8(ne2k->port + DP_BNRY, next);
-	}
-	
-	return frames;
-}
-
-list_t *ne2k_interrupt(ne2k_t *ne2k, uint8_t isr, uint8_t tsr)
-{
-	/* List of received frames */
-	list_t *frames = NULL;
-	
-	if (isr & (ISR_PTX | ISR_TXE)) {
-		if (isr & ISR_TXE)
-			ne2k->stats.send_errors++;
-		else {
-			if (tsr & TSR_PTX)
-				ne2k->stats.send_packets++;
-			
-			if (tsr & TSR_COL)
-				ne2k->stats.collisions++;
-			
-			if (tsr & TSR_ABT)
-				ne2k->stats.send_aborted_errors++;
-			
-			if (tsr & TSR_CRS)
-				ne2k->stats.send_carrier_errors++;
-			
-			if (tsr & TSR_FU) {
-				ne2k->underruns++;
-				if (ne2k->underruns < NE2K_ERL)
-					fprintf(stderr, "%s: FIFO underrun\n", NAME);
-			}
-			
-			if (tsr & TSR_CDH) {
-				ne2k->stats.send_heartbeat_errors++;
-				if (ne2k->stats.send_heartbeat_errors < NE2K_ERL)
-					fprintf(stderr, "%s: CD heartbeat failure\n", NAME);
-			}
-			
-			if (tsr & TSR_OWC)
-				ne2k->stats.send_window_errors++;
-		}
-		
-		fibril_mutex_lock(&ne2k->sq_mutex);
-		
-		if (ne2k->sq.dirty) {
-			/* Prepare the buffer for next packet */
-			ne2k->sq.dirty = false;
-			ne2k->sq.size = 0;
-			
-			/* Signal a next frame to be sent */
-			fibril_condvar_broadcast(&ne2k->sq_cv);
-		} else {
-			ne2k->misses++;
-			if (ne2k->misses < NE2K_ERL)
-				fprintf(stderr, "%s: Spurious PTX interrupt\n", NAME);
-		}
-		
-		fibril_mutex_unlock(&ne2k->sq_mutex);
-	}
-	
-	if (isr & ISR_RXE)
-		ne2k->stats.receive_errors++;
-	
-	if (isr & ISR_CNT) {
-		ne2k->stats.receive_crc_errors +=
-		    pio_read_8(ne2k->port + DP_CNTR0);
-		ne2k->stats.receive_frame_errors +=
-		    pio_read_8(ne2k->port + DP_CNTR1);
-		ne2k->stats.receive_missed_errors +=
-		    pio_read_8(ne2k->port + DP_CNTR2);
-	}
-	
-	if (isr & ISR_PRX)
-		frames = ne2k_receive(ne2k);
-	
-	if (isr & ISR_RST) {
-		/*
-		 * The chip is stopped, and all arrived
-		 * frames are delivered.
-		 */
-		ne2k_reset(ne2k);
-	}
-	
-	/* Unmask interrupts to be processed in the next round */
-	pio_write_8(ne2k->port + DP_IMR,
-	    IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE | IMR_OVWE | IMR_CNTE);
-	
-	return frames;
-}
-
-/** @}
- */
Index: uspace/srv/hw/netif/ne2000/dp8390.h
===================================================================
--- uspace/srv/hw/netif/ne2000/dp8390.h	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,248 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * This code is based upon the NE2000 driver for MINIX,
- * distributed according to a BSD-style license.
- *
- * Copyright (c) 1987, 1997, 2006 Vrije Universiteit
- * Copyright (c) 1992, 1994 Philip Homburg
- * Copyright (c) 1996 G. Falzoni
- *
- */
-
-/** @addtogroup ne2000
- *  @{
- */
-
-/** @file
- *  DP8390 network interface definitions.
- */
-
-#ifndef __NET_NETIF_DP8390_H__
-#define __NET_NETIF_DP8390_H__
-
-#include <fibril_synch.h>
-#include <adt/list.h>
-#include <net/packet.h>
-#include <netif_skel.h>
-
-/** Module name */
-#define NAME  "ne2000"
-
-/** Input/output size */
-#define NE2K_IO_SIZE  0x0020
-
-/** Ethernet address length */
-#define ETH_ADDR  6
-
-/* National Semiconductor DP8390 Network Interface Controller. */
-
-/** Page 0, for reading */
-#define DP_CR     0x00  /**< Command Register */
-#define DP_CLDA0  0x01  /**< Current Local DMA Address 0 */
-#define DP_CLDA1  0x02  /**< Current Local DMA Address 1 */
-#define DP_BNRY   0x03  /**< Boundary Pointer */
-#define DP_TSR    0x04  /**< Transmit Status Register */
-#define DP_NCR    0x05  /**< Number of Collisions Register */
-#define DP_FIFO   0x06  /**< FIFO */
-#define DP_ISR    0x07  /**< Interrupt Status Register */
-#define DP_CRDA0  0x08  /**< Current Remote DMA Address 0 */
-#define DP_CRDA1  0x09  /**< Current Remote DMA Address 1 */
-#define DP_RSR    0x0c  /**< Receive Status Register */
-#define DP_CNTR0  0x0d  /**< Tally Counter 0 */
-#define DP_CNTR1  0x0e  /**< Tally Counter 1 */
-#define DP_CNTR2  0x0f  /**< Tally Counter 2 */
-
-/** Page 0, for writing */
-#define DP_PSTART  0x01  /**< Page Start Register*/
-#define DP_PSTOP   0x02  /**< Page Stop Register */
-#define DP_TPSR    0x04  /**< Transmit Page Start Register */
-#define DP_TBCR0   0x05  /**< Transmit Byte Count Register 0 */
-#define DP_TBCR1   0x06  /**< Transmit Byte Count Register 1 */
-#define DP_RSAR0   0x08  /**< Remote Start Address Register 0 */
-#define DP_RSAR1   0x09  /**< Remote Start Address Register 1 */
-#define DP_RBCR0   0x0a  /**< Remote Byte Count Register 0 */
-#define DP_RBCR1   0x0b  /**< Remote Byte Count Register 1 */
-#define DP_RCR     0x0c  /**< Receive Configuration Register */
-#define DP_TCR     0x0d  /**< Transmit Configuration Register */
-#define DP_DCR     0x0e  /**< Data Configuration Register */
-#define DP_IMR     0x0f  /**< Interrupt Mask Register */
-
-/** Page 1, read/write */
-#define DP_PAR0  0x01  /**< Physical Address Register 0 */
-#define DP_PAR1  0x02  /**< Physical Address Register 1 */
-#define DP_PAR2  0x03  /**< Physical Address Register 2 */
-#define DP_PAR3  0x04  /**< Physical Address Register 3 */
-#define DP_PAR4  0x05  /**< Physical Address Register 4 */
-#define DP_PAR5  0x06  /**< Physical Address Register 5 */
-#define DP_CURR  0x07  /**< Current Page Register */
-#define DP_MAR0  0x08  /**< Multicast Address Register 0 */
-#define DP_MAR1  0x09  /**< Multicast Address Register 1 */
-#define DP_MAR2  0x0a  /**< Multicast Address Register 2 */
-#define DP_MAR3  0x0b  /**< Multicast Address Register 3 */
-#define DP_MAR4  0x0c  /**< Multicast Address Register 4 */
-#define DP_MAR5  0x0d  /**< Multicast Address Register 5 */
-#define DP_MAR6  0x0e  /**< Multicast Address Register 6 */
-#define DP_MAR7  0x0f  /**< Multicast Address Register 7 */
-
-/* Bits in Command Register */
-#define CR_STP       0x01  /**< Stop (software reset) */
-#define CR_STA       0x02  /**< Start (activate NIC) */
-#define CR_TXP       0x04  /**< Transmit Packet */
-#define CR_DMA       0x38  /**< Mask for DMA control */
-#define CR_DM_NOP    0x00  /**< DMA: No Operation */
-#define CR_DM_RR     0x08  /**< DMA: Remote Read */
-#define CR_DM_RW     0x10  /**< DMA: Remote Write */
-#define CR_DM_SP     0x18  /**< DMA: Send Packet */
-#define CR_DM_ABORT  0x20  /**< DMA: Abort Remote DMA Operation */
-#define CR_PS        0xc0  /**< Mask for Page Select */
-#define CR_PS_P0     0x00  /**< Register Page 0 */
-#define CR_PS_P1     0x40  /**< Register Page 1 */
-#define CR_PS_P2     0x80  /**< Register Page 2 */
-#define CR_PS_T1     0xc0  /**< Test Mode Register Map */
-
-/* Bits in Interrupt State Register */
-#define ISR_PRX  0x01  /**< Packet Received with no errors */
-#define ISR_PTX  0x02  /**< Packet Transmitted with no errors */
-#define ISR_RXE  0x04  /**< Receive Error */
-#define ISR_TXE  0x08  /**< Transmit Error */
-#define ISR_OVW  0x10  /**< Overwrite Warning */
-#define ISR_CNT  0x20  /**< Counter Overflow */
-#define ISR_RDC  0x40  /**< Remote DMA Complete */
-#define ISR_RST  0x80  /**< Reset Status */
-
-/* Bits in Interrupt Mask Register */
-#define IMR_PRXE  0x01  /**< Packet Received Interrupt Enable */
-#define IMR_PTXE  0x02  /**< Packet Transmitted Interrupt Enable */
-#define IMR_RXEE  0x04  /**< Receive Error Interrupt Enable */
-#define IMR_TXEE  0x08  /**< Transmit Error Interrupt Enable */
-#define IMR_OVWE  0x10  /**< Overwrite Warning Interrupt Enable */
-#define IMR_CNTE  0x20  /**< Counter Overflow Interrupt Enable */
-#define IMR_RDCE  0x40  /**< DMA Complete Interrupt Enable */
-
-/* Bits in Data Configuration Register */
-#define DCR_WTS        0x01  /**< Word Transfer Select */
-#define DCR_BYTEWIDE   0x00  /**< WTS: byte wide transfers */
-#define DCR_WORDWIDE   0x01  /**< WTS: word wide transfers */
-#define DCR_BOS        0x02  /**< Byte Order Select */
-#define DCR_LTLENDIAN  0x00  /**< BOS: Little Endian */
-#define DCR_BIGENDIAN  0x02  /**< BOS: Big Endian */
-#define DCR_LAS        0x04  /**< Long Address Select */
-#define DCR_BMS        0x08  /**< Burst Mode Select */
-#define DCR_AR         0x10  /**< Autoinitialize Remote */
-#define DCR_FTS        0x60  /**< Fifo Threshold Select */
-#define DCR_2BYTES     0x00  /**< 2 bytes */
-#define DCR_4BYTES     0x40  /**< 4 bytes */
-#define DCR_8BYTES     0x20  /**< 8 bytes */
-#define DCR_12BYTES    0x60  /**< 12 bytes */
-
-/* Bits in Transmit Configuration Register */
-#define TCR_CRC        0x01  /**< Inhibit CRC */
-#define TCR_ELC        0x06  /**< Encoded Loopback Control */
-#define TCR_NORMAL     0x00  /**< ELC: Normal Operation */
-#define TCR_INTERNAL   0x02  /**< ELC: Internal Loopback */
-#define TCR_0EXTERNAL  0x04  /**< ELC: External Loopback LPBK=0 */
-#define TCR_1EXTERNAL  0x06  /**< ELC: External Loopback LPBK=1 */
-#define TCR_ATD        0x08  /**< Auto Transmit Disable */
-#define TCR_OFST       0x10  /**< Collision Offset Enable (be nice) */
-
-/* Bits in Interrupt Status Register */
-#define TSR_PTX  0x01  /**< Packet Transmitted (without error) */
-#define TSR_DFR  0x02  /**< Transmit Deferred (reserved) */
-#define TSR_COL  0x04  /**< Transmit Collided */
-#define TSR_ABT  0x08  /**< Transmit Aborted */
-#define TSR_CRS  0x10  /**< Carrier Sense Lost */
-#define TSR_FU   0x20  /**< FIFO Underrun */
-#define TSR_CDH  0x40  /**< CD Heartbeat */
-#define TSR_OWC  0x80  /**< Out of Window Collision */
-
-/* Bits in Receive Configuration Register */
-#define RCR_SEP  0x01  /**< Save Errored Packets */
-#define RCR_AR   0x02  /**< Accept Runt Packets */
-#define RCR_AB   0x04  /**< Accept Broadcast */
-#define RCR_AM   0x08  /**< Accept Multicast */
-#define RCR_PRO  0x10  /**< Physical Promiscuous */
-#define RCR_MON  0x20  /**< Monitor Mode */
-
-/* Bits in Receive Status Register */
-#define RSR_PRX  0x01  /**< Packet Received Intact */
-#define RSR_CRC  0x02  /**< CRC Error */
-#define RSR_FAE  0x04  /**< Frame Alignment Error */
-#define RSR_FO   0x08  /**< FIFO Overrun */
-#define RSR_MPA  0x10  /**< Missed Packet */
-#define RSR_PHY  0x20  /**< Multicast Address Match */
-#define RSR_DIS  0x40  /**< Receiver Disabled */
-#define RSR_DFR  0x80  /**< In later manuals: Deferring */
-
-typedef struct {
-	/* Device configuration */
-	void *port;
-	void *data_port;
-	int irq;
-	uint8_t mac[ETH_ADDR];
-	
-	uint8_t start_page;  /**< Ring buffer start page */
-	uint8_t stop_page;   /**< Ring buffer stop page */
-	
-	/* Send queue */
-	struct {
-		bool dirty;    /**< Buffer contains a packet */
-		size_t size;   /**< Packet size */
-		uint8_t page;  /**< Starting page of the buffer */
-	} sq;
-	fibril_mutex_t sq_mutex;
-	fibril_condvar_t sq_cv;
-	
-	/* Driver run-time variables */
-	bool probed;
-	bool up;
-	
-	/* Device statistics */
-	device_stats_t stats;
-	uint64_t misses;     /**< Receive frame misses */
-	uint64_t underruns;  /**< FIFO underruns */
-	uint64_t overruns;   /**< FIFO overruns */
-} ne2k_t;
-
-typedef struct {
-	link_t link;
-	packet_t *packet;
-} frame_t;
-
-extern int ne2k_probe(ne2k_t *, void *, int);
-extern int ne2k_up(ne2k_t *);
-extern void ne2k_down(ne2k_t *);
-extern void ne2k_send(ne2k_t *, packet_t *);
-extern list_t *ne2k_interrupt(ne2k_t *, uint8_t, uint8_t);
-
-#endif
-
-/** @}
- */
Index: uspace/srv/hw/netif/ne2000/ne2000.c
===================================================================
--- uspace/srv/hw/netif/ne2000/ne2000.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,410 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * Copyright (c) 2011 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup ne2000
- *  @{
- */
-
-/** @file
- *  NE2000 network interface implementation.
- */
-
-#include <assert.h>
-#include <async.h>
-#include <ddi.h>
-#include <errno.h>
-#include <err.h>
-#include <malloc.h>
-#include <sysinfo.h>
-#include <ns.h>
-#include <ipc/services.h>
-#include <ipc/irc.h>
-#include <net/modules.h>
-#include <packet_client.h>
-#include <adt/measured_strings.h>
-#include <net/device.h>
-#include <netif_skel.h>
-#include <nil_remote.h>
-#include "dp8390.h"
-
-/** Return the device from the interrupt call.
- *
- *  @param[in] call The interrupt call.
- *
- */
-#define IRQ_GET_DEVICE(call)  ((device_id_t) IPC_GET_IMETHOD(call))
-
-/** Return the ISR from the interrupt call.
- *
- * @param[in] call The interrupt call.
- *
- */
-#define IRQ_GET_ISR(call)  ((int) IPC_GET_ARG2(call))
-
-/** Return the TSR from the interrupt call.
- *
- * @param[in] call The interrupt call.
- *
- */
-#define IRQ_GET_TSR(call)  ((int) IPC_GET_ARG3(call))
-
-static bool irc_service = false;
-static async_sess_t *irc_sess = NULL;
-
-/** NE2000 kernel interrupt command sequence.
- *
- */
-static irq_cmd_t ne2k_cmds[] = {
-	{
-		/* Read Interrupt Status Register */
-		.cmd = CMD_PIO_READ_8,
-		.addr = NULL,
-		.dstarg = 2
-	},
-	{
-		/* Mask supported interrupt causes */
-		.cmd = CMD_BTEST,
-		.value = (ISR_PRX | ISR_PTX | ISR_RXE | ISR_TXE | ISR_OVW |
-		    ISR_CNT | ISR_RDC),
-		.srcarg = 2,
-		.dstarg = 3,
-	},
-	{
-		/* Predicate for accepting the interrupt */
-		.cmd = CMD_PREDICATE,
-		.value = 4,
-		.srcarg = 3
-	},
-	{
-		/*
-		 * Mask future interrupts via
-		 * Interrupt Mask Register
-		 */
-		.cmd = CMD_PIO_WRITE_8,
-		.addr = NULL,
-		.value = 0
-	},
-	{
-		/* Acknowledge the current interrupt */
-		.cmd = CMD_PIO_WRITE_A_8,
-		.addr = NULL,
-		.srcarg = 3
-	},
-	{
-		/* Read Transmit Status Register */
-		.cmd = CMD_PIO_READ_8,
-		.addr = NULL,
-		.dstarg = 3
-	},
-	{
-		.cmd = CMD_ACCEPT
-	}
-};
-
-/** NE2000 kernel interrupt code.
- *
- */
-static irq_code_t ne2k_code = {
-	sizeof(ne2k_cmds) / sizeof(irq_cmd_t),
-	ne2k_cmds
-};
-
-/** Handle the interrupt notification.
- *
- * This is the interrupt notification function. It is quarantied
- * that there is only a single instance of this notification
- * function running at one time until the return from the
- * ne2k_interrupt() function (where the interrupts are unmasked
- * again).
- *
- * @param[in] iid  Interrupt notification identifier.
- * @param[in] call Interrupt notification.
- *
- */
-static void irq_handler(ipc_callid_t iid, ipc_call_t *call)
-{
-	device_id_t device_id = IRQ_GET_DEVICE(*call);
-	netif_device_t *device;
-	async_sess_t *nil_sess;
-	ne2k_t *ne2k;
-	
-	fibril_rwlock_read_lock(&netif_globals.lock);
-	
-	nil_sess = netif_globals.nil_sess;
-	
-	if (find_device(device_id, &device) == EOK)
-		ne2k = (ne2k_t *) device->specific;
-	else
-		ne2k = NULL;
-	
-	fibril_rwlock_read_unlock(&netif_globals.lock);
-	
-	if (ne2k != NULL) {
-		list_t *frames =
-		    ne2k_interrupt(ne2k, IRQ_GET_ISR(*call), IRQ_GET_TSR(*call));
-		
-		if (frames != NULL) {
-			while (!list_empty(frames)) {
-				frame_t *frame = list_get_instance(
-				    list_first(frames), frame_t, link);
-				
-				list_remove(&frame->link);
-				nil_received_msg(nil_sess, device_id, frame->packet,
-				    SERVICE_NONE);
-				free(frame);
-			}
-			
-			free(frames);
-		}
-	}
-}
-
-/** Change the network interface state.
- *
- * @param[in,out] device Network interface.
- * @param[in]     state  New state.
- *
- */
-static void change_state(netif_device_t *device, device_state_t state)
-{
-	if (device->state != state) {
-		device->state = state;
-		
-		const char *desc;
-		switch (state) {
-		case NETIF_ACTIVE:
-			desc = "active";
-			break;
-		case NETIF_STOPPED:
-			desc = "stopped";
-			break;
-		default:
-			desc = "unknown";
-		}
-		
-		printf("%s: State changed to %s\n", NAME, desc);
-	}
-}
-
-int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
-    ipc_call_t *answer, size_t *count)
-{
-	return ENOTSUP;
-}
-
-int netif_get_device_stats(device_id_t device_id, device_stats_t *stats)
-{
-	if (!stats)
-		return EBADMEM;
-	
-	netif_device_t *device;
-	int rc = find_device(device_id, &device);
-	if (rc != EOK)
-		return rc;
-	
-	ne2k_t *ne2k = (ne2k_t *) device->specific;
-	
-	memcpy(stats, &ne2k->stats, sizeof(device_stats_t));
-	return EOK;
-}
-
-int netif_get_addr_message(device_id_t device_id, measured_string_t *address)
-{
-	if (!address)
-		return EBADMEM;
-	
-	netif_device_t *device;
-	int rc = find_device(device_id, &device);
-	if (rc != EOK)
-		return rc;
-	
-	ne2k_t *ne2k = (ne2k_t *) device->specific;
-	
-	address->value = ne2k->mac;
-	address->length = ETH_ADDR;
-	return EOK;
-}
-
-int netif_probe_message(device_id_t device_id, int irq, void *io)
-{
-	netif_device_t *device =
-	    (netif_device_t *) malloc(sizeof(netif_device_t));
-	if (!device)
-		return ENOMEM;
-	
-	ne2k_t *ne2k = (ne2k_t *) malloc(sizeof(ne2k_t));
-	if (!ne2k) {
-		free(device);
-		return ENOMEM;
-	}
-	
-	void *port;
-	int rc = pio_enable((void *) io, NE2K_IO_SIZE, &port);
-	if (rc != EOK) {
-		free(ne2k);
-		free(device);
-		return rc;
-	}
-	
-	bzero(device, sizeof(netif_device_t));
-	bzero(ne2k, sizeof(ne2k_t));
-	
-	device->device_id = device_id;
-	device->specific = (void *) ne2k;
-	device->state = NETIF_STOPPED;
-	
-	rc = ne2k_probe(ne2k, port, irq);
-	if (rc != EOK) {
-		printf("%s: No ethernet card found at I/O address %p\n",
-		    NAME, port);
-		free(ne2k);
-		free(device);
-		return rc;
-	}
-	
-	rc = netif_device_map_add(&netif_globals.device_map, device->device_id, device);
-	if (rc != EOK) {
-		free(ne2k);
-		free(device);
-		return rc;
-	}
-	
-	printf("%s: Ethernet card at I/O address %p, IRQ %d, MAC ",
-	    NAME, port, irq);
-	
-	unsigned int i;
-	for (i = 0; i < ETH_ADDR; i++)
-		printf("%02x%c", ne2k->mac[i], i < 5 ? ':' : '\n');
-	
-	return EOK;
-}
-
-int netif_start_message(netif_device_t *device)
-{
-	if (device->state != NETIF_ACTIVE) {
-		ne2k_t *ne2k = (ne2k_t *) device->specific;
-		
-		ne2k_cmds[0].addr = ne2k->port + DP_ISR;
-		ne2k_cmds[3].addr = ne2k->port + DP_IMR;
-		ne2k_cmds[4].addr = ne2k_cmds[0].addr;
-		ne2k_cmds[5].addr = ne2k->port + DP_TSR;
-		
-		int rc = register_irq(ne2k->irq, device->device_id,
-		    device->device_id, &ne2k_code);
-		if (rc != EOK)
-			return rc;
-		
-		rc = ne2k_up(ne2k);
-		if (rc != EOK) {
-			unregister_irq(ne2k->irq, device->device_id);
-			return rc;
-		}
-		
-		change_state(device, NETIF_ACTIVE);
-		
-		if (irc_service) {
-			async_exch_t *exch = async_exchange_begin(irc_sess);
-			async_msg_1(exch, IRC_ENABLE_INTERRUPT, ne2k->irq);
-			async_exchange_end(exch);
-		}
-	}
-	
-	return device->state;
-}
-
-int netif_stop_message(netif_device_t *device)
-{
-	if (device->state != NETIF_STOPPED) {
-		ne2k_t *ne2k = (ne2k_t *) device->specific;
-		
-		ne2k_down(ne2k);
-		unregister_irq(ne2k->irq, device->device_id);
-		change_state(device, NETIF_STOPPED);
-	}
-	
-	return device->state;
-}
-
-int netif_send_message(device_id_t device_id, packet_t *packet,
-    services_t sender)
-{
-	netif_device_t *device;
-	int rc = find_device(device_id, &device);
-	if (rc != EOK)
-		return rc;
-	
-	if (device->state != NETIF_ACTIVE) {
-		netif_pq_release(packet_get_id(packet));
-		return EFORWARD;
-	}
-	
-	ne2k_t *ne2k = (ne2k_t *) device->specific;
-	
-	/*
-	 * Process the packet queue
-	 */
-	
-	do {
-		packet_t *next = pq_detach(packet);
-		ne2k_send(ne2k, packet);
-		netif_pq_release(packet_get_id(packet));
-		packet = next;
-	} while (packet);
-	
-	return EOK;
-}
-
-int netif_initialize(void)
-{
-	sysarg_t apic;
-	sysarg_t i8259;
-	
-	if (((sysinfo_get_value("apic", &apic) == EOK) && (apic))
-	    || ((sysinfo_get_value("i8259", &i8259) == EOK) && (i8259)))
-		irc_service = true;
-	
-	if (irc_service) {
-		while (!irc_sess)
-			irc_sess = service_connect_blocking(EXCHANGE_SERIALIZE,
-			    SERVICE_IRC, 0, 0);
-	}
-	
-	async_set_interrupt_received(irq_handler);
-	
-	return service_register(SERVICE_NE2000);
-}
-
-int main(int argc, char *argv[])
-{
-	/* Start the module */
-	return netif_module_start();
-}
-
-/** @}
- */
Index: uspace/srv/loc/loc.c
===================================================================
--- uspace/srv/loc/loc.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/loc/loc.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -1163,4 +1163,5 @@
 	link_initialize(&service->services);
 	link_initialize(&service->server_services);
+	list_initialize(&service->cat_memb);
 	
 	/* Get unique service ID */
@@ -1288,6 +1289,8 @@
 	cat = category_new("virtual");
 	categ_dir_add_cat(&cdir, cat);
-
-
+	
+	cat = category_new("nic");
+	categ_dir_add_cat(&cdir, cat);
+	
 	return true;
 }
Index: uspace/srv/net/cfg/lo
===================================================================
--- uspace/srv/net/cfg/lo	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,13 +1,0 @@
-# loopback configuration
-
-NAME=lo
-
-NETIF=lo
-NIL=nildummy
-IL=ip
-
-IP_CONFIG=static
-IP_ADDR=127.0.0.1
-IP_NETMASK=255.0.0.0
-
-MTU=15535
Index: uspace/srv/net/cfg/lo.nic
===================================================================
--- uspace/srv/net/cfg/lo.nic	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
+++ uspace/srv/net/cfg/lo.nic	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -0,0 +1,13 @@
+# loopback configuration
+
+NAME=lo
+
+HWPATH=/virt/lo/port0
+NIL=nildummy
+IL=ip
+
+IP_CONFIG=static
+IP_ADDR=127.0.0.1
+IP_NETMASK=255.0.0.0
+
+MTU=15535
Index: uspace/srv/net/cfg/ne2k
===================================================================
--- uspace/srv/net/cfg/ne2k	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,24 +1,0 @@
-# DP8390 (NE2k) configuration
-
-NAME=ne2k
-
-NETIF=ne2000
-NIL=eth
-IL=ip
-
-IRQ=5
-IO=300
-
-# 8023_2_LSAP, 8023_2_SNAP
-ETH_MODE=DIX
-ETH_DUMMY=no
-
-IP_CONFIG=static
-IP_ADDR=10.0.2.15
-IP_ROUTING=yes
-IP_NETMASK=255.255.255.0
-IP_BROADCAST=10.0.2.255
-IP_GATEWAY=10.0.2.2
-ARP=arp
-
-MTU=1500
Index: uspace/srv/net/cfg/ne2k.nic
===================================================================
--- uspace/srv/net/cfg/ne2k.nic	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
+++ uspace/srv/net/cfg/ne2k.nic	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -0,0 +1,21 @@
+# NE2000 configuration
+
+NAME=ne2k
+
+HWPATH=/hw/pci0/00:01.0/ne2k/port0
+NIL=eth
+IL=ip
+
+# 8023_2_LSAP, 8023_2_SNAP
+ETH_MODE=DIX
+ETH_DUMMY=no
+
+IP_CONFIG=static
+IP_ADDR=10.0.2.15
+IP_ROUTING=yes
+IP_NETMASK=255.255.255.240
+IP_BROADCAST=10.0.2.255
+IP_GATEWAY=10.0.2.2
+ARP=arp
+
+MTU=1500
Index: uspace/srv/net/documentation.txt
===================================================================
--- uspace/srv/net/documentation.txt	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,201 +1,0 @@
-/**
-
-\mainpage Networking and TCP/IP Stack for HelenOS system
-
-\section introduction Introduction
-
-<p>
-For the microkernel HelenOS a completely new networking stack was designed.
-The networking stack was intended to implement current basic standards of the TCP/IP Stack.
-Only the minimalistic functionality allowing the stack to function was to be implemented.
-The networking stack is written in C.
-</p>
-<p>
-Please see
-</p>
-<ul>
-	<li>\ref build</li>
-	<li>\ref software</li>
-	<li>\ref running</li>
-	<li>\ref testing</li>
-</ul>
-
-\page build Build from sources
-
-<p>
-To compile the HelenOS from sources (the cross compilers from the <code>build/</code> directory are recommended):
-</p>
-<ol>
-	<li>change the working directory to the HelenOS source directory</li>
-	<li>run <code># make config</code></li>
-	<li>check/change the configuration</li>
-	<li>save and exit the configuration tool</li>
-	<li>run <code># make</code></li>
-</ol>
-<p>
-The <code>image.iso</code> should be created on success.
-</p>
-
-\page running Running the HelenOS with networking
-
-\section netstart Starting the networking
-
-<p>
-After starting the HelenOS boot image in <em>Qemu</em>, the command line appears.
-To run <em>Qemu</em> a script <code>contrib/conf/qemu.sh</code> for Linux or <code>contrib/conf/qemu.bat</code> for Windows in the HelenOS source directory can be used.
-The provided scripts set the needed arguments:
-<br><code>-vga std -M isapc -net nic,model=ne2k_isa -net user -redir udp:8080::8080 -redir udp:8081::8081 -boot d -cdrom image.iso</code><br>
-Additional arguments may be specified on the command line, they override these set.
-</p>
-
-<p>
-The networking stack is started and initialized by running a command
-<br><code># netstart</code><br>
-The networking stack is then started and configured network interfaces are enabled.
-The current configuration is printed out.
-Since that networking applications can be run using the command line as well.
-</p>
-
-\section network Qemu network
-
-<p>
-In the common mode <em>Qemu</em> creates a simple network with a gateway and settles the guest system in.
-The network is 10.0.2.*, the gateway's address 10.0.2.2 and the guest system has 10.0.2.15.
-%Even this simple setting was a bit hard to find in the documentation.
-Therefore a static configuration is possible and no additional DHCP nor BOOTP implementations are necessary.
-On the other hand the guest system is behind a firewall.
-<em>Qemu</em> may be configured to forward some ports to the guest system and allows all outgoing traffic except ICMP and ARP protocols, so you can ping only the gateway.
-</p>
-
-\section applications Applications
-
-<p>
-A few networking applications are located in the app/ directory.
-Common functions for parsing command line arguments and printing textual networking error messages are located in that directory as well.
-The networking applications should be built with the libsocket library located in the socket/libsocket.a file.
-They can use functions and definitions from the include/socket.h header file which contains socket API and further includes:
-</p>
-<ul>
-	<li>include/byteorder.h containing byte order manipulation,</li>
-	<li>include/in.h containing IPv4 socket address structure,</li>
-	<li>include/in6.h containing IPv6 socket address structure,</li>
-	<li>include/inet.h containing socket address structure and parsing functions,</li>
-	<li>include/socket codes.h containing address and protocol families and socket types and option levels, and</li>
-	<li>include/socket errno.h containing socket and general error codes.</li>
-</ul>
-
-\page software Software prerequisites
-
-<p>
-The networking and TCP/IP stack is implemented for the ia32 architecture on top of HelenOS 0.4.1 (Escalopino), the most current stable release of HelenOS.
-So far the only one operational network interface supported is in Qemu 0.10.2 and newer.
-To run <em>Qemu</em> a script contrib/conf/qemu.sh for Linux or contrib/conf/qemu.bat for Windows in the HelenOS source directory can be used.
-The qemu and its libraries have to be installed and in the path.
-These scripts set all the necessary parameters
-with some ports redirected from the local host to the guest system.
-For testing purposes at least a low level communication application is recommended, N.E.T., netcat etc.
-</p>
-<p>
-In order to build HelenOS and the networking stack from sources a few tools are
-required:
-<ul>
-	<li>binutils in version 2.19.1,</li>
-	<li>gcc–core in version 4.3.3 11,</li>
-	<li>gcc–objc in version 4.3.3, and</li>
-	<li>gcc–g++ in version 4.3.3.</li>
-</ul>
-<p>
-All these can be downloaded and installed as cross–compilers on Linux using a script contrib/toolchain.sh in the HelenOS source directory.
-In addition rats, a static source code analyzer, and Doxygen, a documentation generator, were used.
-All development was tracked in the HelenOS subversion repository.
-</p>
-<ul>
-	<li>HelenOS website: <a href="http://www.helenos.org/" title="HelenOS website">http://www.helenos.org/</a></li>
-	<li><em>Qemu</em> website: <a href="http://www.qemu.org/" title="Qemu website">http://www.qemu.org/</a></li>
-	<li><em>binutils</em> website: <a href="http://www.gnu.org/software/binutils/" title="binutils website">http://www.gnu.org/software/binutils/</a></li>
-	<li><em>GCC</em> website: <a href="http://gcc.gnu.org/" title="GCC website">http://gcc.gnu.org/</a></li>
-	<li><em>RATS</em> website: <a href="http://www.fortify.com/security-resources/rats.jsp" title="RATS website">http://www.fortify.com/security-resources/rats.jsp</a></li>
-	<li><em>Doxygen</em> website: <a href="http://www.stack.nl/ dimitri/doxygen/index.html" title="Doxygen website">http://www.stack.nl/ dimitri/doxygen/index.html</a></li>
-	<li><em>Subversion</em> website: <a href="http://subversion.tigris.org/" title="Subversion website">http://subversion.tigris.org/</a></li>
-</ul>
-
-\page testing Testing scenarios
-
-<p>
-The scenarios contain the following shortcuts:
-</p>
-<ul>
-	<li>g for the quest system, HelenOS in <em>Qemu</em></li>
-	<li>h for the host system</li>
-	<li>n for the <em>NET</em> application</li>
-	<li>e for echo echo application run in HelenOS</li>
-</ul>
-
-\section scenarios Testing scenarios
-<ul>
-	<li>UDP
-		<ol>
-			<li>g #netstart</li>
-			<li>h wine net.exe (->n) (or net.exe)</li>
-			<li>n set 127.0.0.1:8080 address and port, BuiltinUDP protocol</li>
-			<li>n send some data (an ARP will be generated and the original packet gets lost)</li>
-			<li>n send some data (the port is unreachable and the packet is discarded)</li>
-			<li>g #echo -p 8080 -c 3 -v (->e)</li>
-			<li>g prints Listening</li>
-			<li>n send some data</li>
-			<li>e prints received data</li>
-			<li>h prints reply</li>
-			<li>n click disconnect</li>
-			<li>n set :8081 port</li>
-			<li>n send some data</li>
-			<li>n click disconnect</li>
-			<li>n set :8080 port</li>
-			<li>count-1 times:
-				<ol>
-					<li>n send some data</li>
-					<li>e prints received data</li>
-					<li>h prints reply</li>
-				</ol>
-			</li>
-			<li>e prints Exiting</li>
-			<li>e quits</li>
-			<li>n send some data (the port is unreachable and the packet is discarded)</li>
-		</ol>
-	</li>
-	<li>ICMP echo to 10.0.2.2
-		<ol>
-			<li>g #netstart</li>
-			<li>g #ping 10.0.2.2 (->p)</li>
-			<li>g prints ARP request for 10.0.2.2</li>
-			<li>g prints ARP reply from 10.0.2.2</li>
-			<li>p prints timeouted</li>
-			<li>p prints round trip time</li>
-			<li>p prints round trip time</li>
-			<li>p quits</li>
-		</ol>
-	</li>
-	<li>ICMP echo to 127.0.0.1
-		<ol>
-			<li>g #netstart</li>
-			<li>g #ping 127.0.0.1 (->p)</li>
-			<li>p prints round trip time</li>
-			<li>p prints round trip time</li>
-			<li>p prints round trip time</li>
-			<li>p quits</li>
-		</ol>
-	</li>
-	<li>ICMP with no internet on the host system (!)
-		<ol>
-			<li>g #netstart</li>
-			<li>g #ping 123.123.123.3 (->p)</li>
-			<li>g prints ARP request for 10.0.2.2</li>
-			<li>g prints ARP reply from 10.0.2.2</li>
-			<li>p prints timeouted</li>
-			<li>p prints destination unreachable</li>
-			<li>p prints destination unreachable</li>
-			<li>p quits</li>
-		</ol>
-	</li>
-</ul>
-
-*/
Index: uspace/srv/net/il/arp/arp.c
===================================================================
--- uspace/srv/net/il/arp/arp.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/il/arp/arp.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -174,12 +174,6 @@
 		    count);
 		
-		if (device) {
+		if (device)
 			arp_clear_device(device);
-			if (device->addr_data)
-				free(device->addr_data);
-			
-			if (device->broadcast_data)
-				free(device->broadcast_data);
-		}
 	}
 	
@@ -190,6 +184,6 @@
 }
 
-static int arp_clear_address_req(device_id_t device_id, services_t protocol,
-    measured_string_t *address)
+static int arp_clear_address_req(nic_device_id_t device_id,
+    services_t protocol, measured_string_t *address)
 {
 	fibril_mutex_lock(&arp_globals.lock);
@@ -218,5 +212,5 @@
 }
 
-static int arp_clear_device_req(device_id_t device_id)
+static int arp_clear_device_req(nic_device_id_t device_id)
 {
 	fibril_mutex_lock(&arp_globals.lock);
@@ -289,5 +283,5 @@
  *
  */
-static int arp_receive_message(device_id_t device_id, packet_t *packet)
+static int arp_receive_message(nic_device_id_t device_id, packet_t *packet)
 {
 	int rc;
@@ -365,5 +359,5 @@
 			memcpy(src_proto, proto->addr->value,
 			    header->protocol_length);
-			memcpy(src_hw, device->addr->value,
+			memcpy(src_hw, device->addr,
 			    device->packet_dimension.addr_len);
 			memcpy(des_hw, trans->hw_addr->value,
@@ -393,5 +387,5 @@
  *
  */
-static int arp_mtu_changed_message(device_id_t device_id, size_t mtu)
+static int arp_mtu_changed_message(nic_device_id_t device_id, size_t mtu)
 {
 	fibril_mutex_lock(&arp_globals.lock);
@@ -409,4 +403,36 @@
 	printf("%s: Device %d changed MTU to %zu\n", NAME, device_id, mtu);
 	
+	return EOK;
+}
+
+static int arp_addr_changed_message(nic_device_id_t device_id)
+{
+	uint8_t addr_buffer[NIC_MAX_ADDRESS_LENGTH];
+	size_t length;
+	ipc_callid_t data_callid;
+	if (!async_data_write_receive(&data_callid, &length)) {
+		async_answer_0(data_callid, EINVAL);
+		return EINVAL;
+	}
+	if (length > NIC_MAX_ADDRESS_LENGTH) {
+		async_answer_0(data_callid, ELIMIT);
+		return ELIMIT;
+	}
+	if (async_data_write_finalize(data_callid, addr_buffer, length) != EOK) {
+		return EINVAL;
+	}
+
+	fibril_mutex_lock(&arp_globals.lock);
+
+	arp_device_t *device = arp_cache_find(&arp_globals.cache, device_id);
+	if (!device) {
+		fibril_mutex_unlock(&arp_globals.lock);
+		return ENOENT;
+	}
+
+	memcpy(device->addr, addr_buffer, length);
+	device->addr_len = length;
+
+	fibril_mutex_unlock(&arp_globals.lock);
 	return EOK;
 }
@@ -456,4 +482,7 @@
 			async_answer_0(iid, (sysarg_t) rc);
 			break;
+		case NET_IL_ADDR_CHANGED:
+			rc = arp_addr_changed_message(IPC_GET_DEVICE(*icall));
+			async_answer_0(iid, (sysarg_t) rc);
 		
 		default:
@@ -483,5 +512,5 @@
  *
  */
-static int arp_device_message(device_id_t device_id, services_t service,
+static int arp_device_message(nic_device_id_t device_id, services_t service,
     services_t protocol, measured_string_t *address)
 {
@@ -586,24 +615,26 @@
 		
 		/* Get hardware address */
-		rc = nil_get_addr_req(device->sess, device_id, &device->addr,
-		    &device->addr_data);
-		if (rc != EOK) {
+		int len = nil_get_addr_req(device->sess, device_id, device->addr,
+		    NIC_MAX_ADDRESS_LENGTH);
+		if (len < 0) {
 			fibril_mutex_unlock(&arp_globals.lock);
 			arp_protos_destroy(&device->protos, free);
 			free(device);
-			return rc;
-		}
+			return len;
+		}
+		
+		device->addr_len = len;
 		
 		/* Get broadcast address */
-		rc = nil_get_broadcast_addr_req(device->sess, device_id,
-		    &device->broadcast_addr, &device->broadcast_data);
-		if (rc != EOK) {
-			fibril_mutex_unlock(&arp_globals.lock);
-			free(device->addr);
-			free(device->addr_data);
+		len = nil_get_broadcast_addr_req(device->sess, device_id,
+		    device->broadcast_addr, NIC_MAX_ADDRESS_LENGTH);
+		if (len < 0) {
+			fibril_mutex_unlock(&arp_globals.lock);
 			arp_protos_destroy(&device->protos, free);
 			free(device);
-			return rc;
-		}
+			return len;
+		}
+		
+		device->broadcast_addr_len = len;
 		
 		rc = arp_cache_add(&arp_globals.cache, device->device_id,
@@ -611,8 +642,4 @@
 		if (rc != EOK) {
 			fibril_mutex_unlock(&arp_globals.lock);
-			free(device->addr);
-			free(device->addr_data);
-			free(device->broadcast_addr);
-			free(device->broadcast_data);
 			arp_protos_destroy(&device->protos, free);
 			free(device);
@@ -640,9 +667,9 @@
 }
 
-static int arp_send_request(device_id_t device_id, services_t protocol,
+static int arp_send_request(nic_device_id_t device_id, services_t protocol,
     measured_string_t *target, arp_device_t *device, arp_proto_t *proto)
 {
 	/* ARP packet content size = header + (address + translation) * 2 */
-	size_t length = 8 + 2 * (proto->addr->length + device->addr->length);
+	size_t length = 8 + 2 * (proto->addr->length + device->addr_len);
 	if (length > device->packet_dimension.content)
 		return ELIMIT;
@@ -661,5 +688,5 @@
 	
 	header->hardware = htons(device->hardware);
-	header->hardware_length = (uint8_t) device->addr->length;
+	header->hardware_length = (uint8_t) device->addr_len;
 	header->protocol = htons(protocol_map(device->service, protocol));
 	header->protocol_length = (uint8_t) proto->addr->length;
@@ -667,17 +694,16 @@
 	
 	length = sizeof(arp_header_t);
-	
-	memcpy(((uint8_t *) header) + length, device->addr->value,
-	    device->addr->length);
-	length += device->addr->length;
+	memcpy(((uint8_t *) header) + length, device->addr,
+	    device->addr_len);
+	length += device->addr_len;
 	memcpy(((uint8_t *) header) + length, proto->addr->value,
 	    proto->addr->length);
 	length += proto->addr->length;
-	bzero(((uint8_t *) header) + length, device->addr->length);
-	length += device->addr->length;
+	bzero(((uint8_t *) header) + length, device->addr_len);
+	length += device->addr_len;
 	memcpy(((uint8_t *) header) + length, target->value, target->length);
 	
-	int rc = packet_set_addr(packet, (uint8_t *) device->addr->value,
-	    (uint8_t *) device->broadcast_addr->value, device->addr->length);
+	int rc = packet_set_addr(packet, device->addr, device->broadcast_addr,
+	    device->addr_len);
 	if (rc != EOK) {
 		pq_release_remote(arp_globals.net_sess, packet_get_id(packet));
@@ -704,5 +730,5 @@
  *
  */
-static int arp_translate_message(device_id_t device_id, services_t protocol,
+static int arp_translate_message(nic_device_id_t device_id, services_t protocol,
     measured_string_t *target, measured_string_t **translation)
 {
Index: uspace/srv/net/il/arp/arp.h
===================================================================
--- uspace/srv/net/il/arp/arp.h	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/il/arp/arp.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -92,13 +92,13 @@
 struct arp_device {
 	/** Actual device hardware address. */
-	measured_string_t *addr;
-	/** Actual device hardware address data. */
-	uint8_t *addr_data;
+	uint8_t addr[NIC_MAX_ADDRESS_LENGTH];
+	/** Actual device hardware address length. */
+	size_t addr_len;
 	/** Broadcast device hardware address. */
-	measured_string_t *broadcast_addr;
-	/** Broadcast device hardware address data. */
-	uint8_t *broadcast_data;
+	uint8_t broadcast_addr[NIC_MAX_ADDRESS_LENGTH];
+	/** Broadcast device hardware address length. */
+	size_t broadcast_addr_len;
 	/** Device identifier. */
-	device_id_t device_id;
+	nic_device_id_t device_id;
 	/** Hardware type. */
 	hw_type_t hardware;
Index: uspace/srv/net/il/ip/ip.c
===================================================================
--- uspace/srv/net/il/ip/ip.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/il/ip/ip.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -354,5 +354,5 @@
 	ip_netif->routing = NET_DEFAULT_IP_ROUTING;
 	configuration = &names[0];
-
+	
 	/* Get configuration */
 	rc = net_get_device_conf_req(ip_globals.net_sess, ip_netif->device_id,
@@ -406,5 +406,5 @@
 			return ENOTSUP;
 		}
-
+		
 		if (configuration[6].value) {
 			ip_netif->arp = get_running_module(&ip_globals.modules,
@@ -417,10 +417,11 @@
 			}
 		}
+		
 		if (configuration[7].value)
 			ip_netif->routing = (configuration[7].value[0] == 'y');
-
+		
 		net_free_settings(configuration, data);
 	}
-
+	
 	/* Bind netif service which also initializes the device */
 	ip_netif->sess = nil_bind_service(ip_netif->service,
@@ -432,5 +433,5 @@
 		return ENOENT;
 	}
-
+	
 	/* Has to be after the device netif module initialization */
 	if (ip_netif->arp) {
@@ -448,5 +449,5 @@
 		}
 	}
-
+	
 	/* Get packet dimensions */
 	rc = nil_packet_size_req(ip_netif->sess, ip_netif->device_id,
@@ -461,5 +462,5 @@
 		ip_netif->packet_dimension.content = IP_MIN_CONTENT;
 	}
-
+	
 	index = ip_netifs_add(&ip_globals.netifs, ip_netif->device_id, ip_netif);
 	if (index < 0)
@@ -478,9 +479,9 @@
 		printf("%s: Default gateway (%s)\n", NAME, defgateway);
 	}
-
+	
 	return EOK;
 }
 
-static int ip_device_req_local(device_id_t device_id, services_t netif)
+static int ip_device_req_local(nic_device_id_t device_id, services_t netif)
 {
 	ip_netif_t *ip_netif;
@@ -498,9 +499,9 @@
 		return rc;
 	}
-
+	
 	ip_netif->device_id = device_id;
 	ip_netif->service = netif;
-	ip_netif->state = NETIF_STOPPED;
-
+	ip_netif->state = NIC_STATE_STOPPED;
+	
 	fibril_rwlock_write_lock(&ip_globals.netifs_lock);
 
@@ -594,5 +595,5 @@
 	while (index >= 0) {
 		netif = ip_netifs_get_index(&ip_globals.netifs, index);
-		if (netif && (netif->state == NETIF_ACTIVE)) {
+		if (netif && (netif->state == NIC_STATE_ACTIVE)) {
 			route = ip_netif_find_route(netif, destination);
 			if (route)
@@ -1142,5 +1143,5 @@
 }
 
-static int ip_send_msg_local(device_id_t device_id, packet_t *packet,
+static int ip_send_msg_local(nic_device_id_t device_id, packet_t *packet,
     services_t sender, services_t error)
 {
@@ -1258,5 +1259,6 @@
  * @return		ENOENT if device is not found.
  */
-static int ip_device_state_message(device_id_t device_id, device_state_t state)
+static int ip_device_state_message(nic_device_id_t device_id,
+    nic_device_state_t state)
 {
 	ip_netif_t *netif;
@@ -1272,5 +1274,6 @@
 	fibril_rwlock_write_unlock(&ip_globals.netifs_lock);
 
-	printf("%s: Device %d changed state to %d\n", NAME, device_id, state);
+	printf("%s: Device %d changed state to '%s'\n", NAME, device_id,
+	    nic_device_state_to_string(state));
 
 	return EOK;
@@ -1312,5 +1315,5 @@
  *			tl_received_msg() function.
  */
-static int ip_deliver_local(device_id_t device_id, packet_t *packet,
+static int ip_deliver_local(nic_device_id_t device_id, packet_t *packet,
     ip_header_t *header, services_t error)
 {
@@ -1413,5 +1416,5 @@
  *			is disabled.
  */
-static int ip_process_packet(device_id_t device_id, packet_t *packet)
+static int ip_process_packet(nic_device_id_t device_id, packet_t *packet)
 {
 	ip_header_t *header;
@@ -1514,5 +1517,5 @@
  *
  */
-static int ip_packet_size_message(device_id_t device_id, size_t *addr_len,
+static int ip_packet_size_message(nic_device_id_t device_id, size_t *addr_len,
     size_t *prefix, size_t *content, size_t *suffix)
 {
@@ -1572,5 +1575,5 @@
  * @return		ENOENT if device is not found.
  */
-static int ip_mtu_changed_message(device_id_t device_id, size_t mtu)
+static int ip_mtu_changed_message(nic_device_id_t device_id, size_t mtu)
 {
 	ip_netif_t *netif;
@@ -1629,5 +1632,8 @@
 			async_answer_0(iid, (sysarg_t) rc);
 			break;
-		
+		case NET_IL_ADDR_CHANGED:
+			async_answer_0(iid, (sysarg_t) EOK);
+			break;
+
 		default:
 			async_answer_0(iid, (sysarg_t) ENOTSUP);
@@ -1689,5 +1695,5 @@
 }
 
-static int ip_add_route_req_local(device_id_t device_id, in_addr_t address,
+static int ip_add_route_req_local(nic_device_id_t device_id, in_addr_t address,
     in_addr_t netmask, in_addr_t gateway)
 {
@@ -1723,5 +1729,6 @@
 }
 
-static int ip_set_gateway_req_local(device_id_t device_id, in_addr_t gateway)
+static int ip_set_gateway_req_local(nic_device_id_t device_id,
+    in_addr_t gateway)
 {
 	ip_netif_t *netif;
@@ -1757,5 +1764,5 @@
  *
  */
-static int ip_received_error_msg_local(device_id_t device_id,
+static int ip_received_error_msg_local(nic_device_id_t device_id,
     packet_t *packet, services_t target, services_t error)
 {
@@ -1818,5 +1825,5 @@
 static int ip_get_route_req_local(ip_protocol_t protocol,
     const struct sockaddr *destination, socklen_t addrlen,
-    device_id_t *device_id, void **header, size_t *headerlen)
+    nic_device_id_t *device_id, void **header, size_t *headerlen)
 {
 	struct sockaddr_in *address_in;
@@ -1909,5 +1916,5 @@
 	size_t suffix;
 	size_t content;
-	device_id_t device_id;
+	nic_device_id_t device_id;
 	int rc;
 	
Index: uspace/srv/net/il/ip/ip.h
===================================================================
--- uspace/srv/net/il/ip/ip.h	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/il/ip/ip.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -92,5 +92,5 @@
 	in_addr_t broadcast;
 	/** Device identifier. */
-	device_id_t device_id;
+	nic_device_id_t device_id;
 	/** Indicates whether using DHCP. */
 	int dhcp;
@@ -108,5 +108,5 @@
 	services_t service;
 	/** Device state. */
-	device_state_t state;
+	nic_device_state_t state;
 };
 
Index: uspace/srv/net/net/Makefile
===================================================================
--- uspace/srv/net/net/Makefile	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/net/Makefile	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -30,6 +30,6 @@
 USPACE_PREFIX = ../../..
 ROOT_PATH = $(USPACE_PREFIX)/..
-LIBS = $(LIBNET_PREFIX)/libnet.a $(LIBPACKET_PREFIX)/libpacket.a
-EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include -I$(LIBPACKET_PREFIX)/include
+LIBS = $(LIBNET_PREFIX)/libnet.a
+EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
 
 COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
@@ -43,5 +43,5 @@
 SOURCES = \
 	net.c \
-	net_standalone.c
+	packet_server.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/net/net.c
===================================================================
--- uspace/srv/net/net/net.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/net/net.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2009 Lukas Mejdrech
+ * Copyright (c) 2011 Radim Vansa
  * All rights reserved.
  *
@@ -31,16 +32,14 @@
  */
 
-/** @file
- * Networking subsystem central module implementation.
- *
- */
-
+#include <assert.h>
 #include <async.h>
 #include <ctype.h>
 #include <ddi.h>
 #include <errno.h>
+#include <str_error.h>
 #include <malloc.h>
 #include <stdio.h>
 #include <str.h>
+#include <devman.h>
 #include <str_error.h>
 #include <ns.h>
@@ -49,6 +48,6 @@
 #include <ipc/net_net.h>
 #include <ipc/il.h>
+#include <ipc/ip.h>
 #include <ipc/nil.h>
-#include <net/modules.h>
 #include <net/packet.h>
 #include <net/device.h>
@@ -57,15 +56,15 @@
 #include <adt/measured_strings.h>
 #include <adt/module_map.h>
-#include <netif_remote.h>
 #include <nil_remote.h>
 #include <net_interface.h>
 #include <ip_interface.h>
+#include <device/nic.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <cfg.h>
 #include "net.h"
-
-/** Networking module name. */
-#define NAME  "net"
-
-/** File read buffer size. */
-#define BUFFER_SIZE  256
+#include "packet_server.h"
+
+#define MAX_PATH_LENGTH  1024
 
 /** Networking module global data. */
@@ -74,6 +73,4 @@
 GENERIC_CHAR_MAP_IMPLEMENT(measured_strings, measured_string_t);
 DEVICE_MAP_IMPLEMENT(netifs, netif_t);
-
-static int startup(void);
 
 /** Add the configured setting to the configuration map.
@@ -87,6 +84,6 @@
  *
  */
-int add_configuration(measured_strings_t *configuration, const uint8_t *name,
-    const uint8_t *value)
+static int add_configuration(measured_strings_t *configuration,
+    const uint8_t *name, const uint8_t *value)
 {
 	int rc;
@@ -109,70 +106,10 @@
 /** Generate new system-unique device identifier.
  *
- * @return		The system-unique devic identifier.
- */
-static device_id_t generate_new_device_id(void)
+ * @return The system-unique devic identifier.
+ *
+ */
+static nic_device_id_t generate_new_device_id(void)
 {
 	return device_assign_devno();
-}
-
-static int parse_line(measured_strings_t *configuration, uint8_t *line)
-{
-	int rc;
-	
-	/* From the beginning */
-	uint8_t *name = line;
-	
-	/* Skip comments and blank lines */
-	if ((*name == '#') || (*name == '\0'))
-		return EOK;
-	
-	/* Skip spaces */
-	while (isspace(*name))
-		name++;
-	
-	/* Remember the name start */
-	uint8_t *value = name;
-	
-	/* Skip the name */
-	while (isalnum(*value) || (*value == '_'))
-		value++;
-	
-	if (*value == '=') {
-		/* Terminate the name */
-		*value = '\0';
-	} else {
-		/* Terminate the name */
-		*value = '\0';
-		
-		/* Skip until '=' */
-		value++;
-		while ((*value) && (*value != '='))
-			value++;
-		
-		/* Not found? */
-		if (*value != '=')
-			return EINVAL;
-	}
-	
-	value++;
-	
-	/* Skip spaces */
-	while (isspace(*value))
-		value++;
-	
-	/* Create a bulk measured string till the end */
-	measured_string_t *setting =
-	    measured_string_create_bulk(value, 0);
-	if (!setting)
-		return ENOMEM;
-	
-	/* Add the configuration setting */
-	rc = measured_strings_add(configuration, name, 0, setting);
-	if (rc != EOK) {
-		free(setting);
-		return rc;
-	}
-	
-	return EOK;
 }
 
@@ -182,50 +119,26 @@
 	printf("%s: Reading configuration file %s/%s\n", NAME, directory, filename);
 	
-	/* Construct the full filename */
-	char fname[BUFFER_SIZE];
-	if (snprintf(fname, BUFFER_SIZE, "%s/%s", directory, filename) > BUFFER_SIZE)
-		return EOVERFLOW;
-	
-	/* Open the file */
-	FILE *cfg = fopen(fname, "r");
-	if (!cfg)
+	cfg_file_t cfg;
+	int rc = cfg_load_path(directory, filename, &cfg);
+	if (rc != EOK)
+		return rc;
+	
+	if (cfg_anonymous(&cfg) == NULL) {
+		cfg_unload(&cfg);
 		return ENOENT;
-	
-	/*
-	 * Read the configuration line by line
-	 * until an error or the end of file
-	 */
-	unsigned int line_number = 0;
-	size_t index = 0;
-	uint8_t line[BUFFER_SIZE];
-	
-	while (!ferror(cfg) && !feof(cfg)) {
-		int read = fgetc(cfg);
-		if ((read > 0) && (read != '\n') && (read != '\r')) {
-			if (index >= BUFFER_SIZE) {
-				line[BUFFER_SIZE - 1] = '\0';
-				fprintf(stderr, "%s: Configuration line %u too "
-				    "long: %s\n", NAME, line_number, (char *) line);
-				
-				/* No space left in the line buffer */
-				return EOVERFLOW;
-			}
-			/* Append the character */
-			line[index] = (uint8_t) read;
-			index++;
-		} else {
-			/* On error or new line */
-			line[index] = '\0';
-			line_number++;
-			if (parse_line(configuration, line) != EOK) {
-				fprintf(stderr, "%s: Configuration error on "
-				    "line %u: %s\n", NAME, line_number, (char *) line);
-			}
-			
-			index = 0;
+	}
+	
+	cfg_section_foreach(cfg_anonymous(&cfg), link) {
+		const cfg_entry_t *entry = cfg_entry_instance(link);
+		
+		rc = add_configuration(configuration,
+		    (uint8_t *) entry->key, (uint8_t *) entry->value);
+		if (rc != EOK) {
+			cfg_unload(&cfg);
+			return rc;
 		}
 	}
 	
-	fclose(cfg);
+	cfg_unload(&cfg);
 	return EOK;
 }
@@ -255,98 +168,4 @@
 	return read_configuration_file(CONF_DIR, CONF_GENERAL_FILE,
 	    &net_globals.configuration);
-}
-
-/** Initialize the networking module.
- *
- * @param[in] client_connection The client connection processing
- *                              function. The module skeleton propagates
- *                              its own one.
- *
- * @return EOK on success.
- * @return ENOMEM if there is not enough memory left.
- *
- */
-static int net_initialize(async_client_conn_t client_connection)
-{
-	int rc;
-	
-	netifs_initialize(&net_globals.netifs);
-	char_map_initialize(&net_globals.netif_names);
-	modules_initialize(&net_globals.modules);
-	measured_strings_initialize(&net_globals.configuration);
-	
-	/* TODO: dynamic configuration */
-	rc = read_configuration();
-	if (rc != EOK)
-		return rc;
-	
-	rc = add_module(NULL, &net_globals.modules, (uint8_t *) LO_NAME,
-	    (uint8_t *) LO_FILENAME, SERVICE_LO, 0, connect_to_service);
-	if (rc != EOK)
-		return rc;
-	
-	rc = add_module(NULL, &net_globals.modules, (uint8_t *) NE2000_NAME,
-	    (uint8_t *) NE2000_FILENAME, SERVICE_NE2000, 0, connect_to_service);
-	if (rc != EOK)
-		return rc;
-	
-	rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,
-	    (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
-	if (rc != EOK)
-		return rc;
-	
-	rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,
-	    (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
-	if (rc != EOK)
-		return rc;
-	
-	/* Build specific initialization */
-	return net_initialize_build(client_connection);
-}
-
-/** Start the networking module.
- *
- * Initializes the client connection serving function,
- * initializes the module, registers the module service
- * and starts the async manager, processing IPC messages
- * in an infinite loop.
- *
- * @param[in] client_connection The client connection
- *                              processing function. The
- *                              module skeleton propagates
- *                              its own one.
- *
- * @return EOK on successful module termination.
- * @return Other error codes as defined for the net_initialize() function.
- * @return Other error codes as defined for the REGISTER_ME() macro function.
- *
- */
-static int net_module_start(async_client_conn_t client_connection)
-{
-	int rc;
-	
-	async_set_client_connection(client_connection);
-	rc = pm_init();
-	if (rc != EOK)
-		return rc;
-	
-	rc = net_initialize(client_connection);
-	if (rc != EOK)
-		goto out;
-	
-	rc = service_register(SERVICE_NETWORKING);
-	if (rc != EOK)
-		goto out;
-	
-	rc = startup();
-	if (rc != EOK)
-		goto out;
-	
-	task_retval(0);
-	async_manager();
-
-out:
-	pm_destroy();
-	return rc;
 }
 
@@ -364,8 +183,8 @@
  */
 static int net_get_conf(measured_strings_t *netif_conf,
-    measured_string_t *configuration, size_t count, uint8_t **data)
-{
-	if (data)
-		*data = NULL;
+    measured_string_t *configuration, size_t count)
+{
+	if ((!configuration) || (count <= 0))
+			return EINVAL;
 	
 	size_t index;
@@ -389,28 +208,65 @@
 }
 
-static int net_get_conf_req_local(measured_string_t **configuration,
-    size_t count, uint8_t **data)
-{
-	if (!configuration || (count <= 0))
-		return EINVAL;
-	
-	return net_get_conf(NULL, *configuration, count, data);
-}
-
-static int net_get_device_conf_req_local(device_id_t device_id,
-    measured_string_t **configuration, size_t count, uint8_t **data)
-{
-	if ((!configuration) || (count == 0))
-		return EINVAL;
-
+static int net_get_device_conf(nic_device_id_t device_id,
+    measured_string_t *configuration, size_t count)
+{
 	netif_t *netif = netifs_find(&net_globals.netifs, device_id);
 	if (netif)
-		return net_get_conf(&netif->configuration, *configuration, count, data);
+		return net_get_conf(&netif->configuration, configuration, count);
 	else
-		return net_get_conf(NULL, *configuration, count, data);
-}
-
-void net_free_settings(measured_string_t *settings, uint8_t *data)
-{
+		return net_get_conf(NULL, configuration, count);
+}
+
+static int net_get_devices(measured_string_t **devices, size_t *dev_count)
+{
+	if (!devices)
+		return EBADMEM;
+	
+	size_t max_count = netifs_count(&net_globals.netifs);
+	*devices = malloc(max_count * sizeof(measured_string_t));
+	if (*devices == NULL)
+		return ENOMEM;
+	
+	size_t count = 0;
+	for (size_t i = 0; i < max_count; i++) {
+		netif_t *item = netifs_get_index(&net_globals.netifs, i);
+		if (item->sess != NULL) {
+			/* 
+			 * Use format "device_id:device_name"
+			 * FIXME: This typecasting looks really ugly
+			 */
+			(*devices)[count].length = asprintf(
+			    (char **) &((*devices)[count].value),
+			    NIC_DEVICE_PRINT_FMT ":%s", item->id,
+			    (const char *) item->name);
+			count++;
+		}
+	}
+	
+	*dev_count = (size_t) count;
+	return EOK;
+}
+
+static int net_get_devices_count()
+{
+	size_t max_count = netifs_count(&net_globals.netifs);
+	
+	size_t count = 0;
+	for (size_t i = 0; i < max_count; i++) {
+		netif_t *item = netifs_get_index(&net_globals.netifs, i);
+		if (item->sess != NULL)
+			count++;
+	}
+	
+	return count;
+}
+
+static void net_free_devices(measured_string_t *devices, size_t count)
+{
+	size_t i;
+	for (i = 0; i < count; ++i)
+		free(devices[i].value);
+	
+	free(devices);
 }
 
@@ -431,25 +287,24 @@
  *
  */
-static int start_device(netif_t *netif)
-{
-	int rc;
-	
-	/* Mandatory netif */
-	measured_string_t *setting =
-	    measured_strings_find(&netif->configuration, (uint8_t *) CONF_NETIF, 0);
-	
-	netif->driver = get_running_module(&net_globals.modules, setting->value);
-	if (!netif->driver) {
-		fprintf(stderr, "%s: Failed to start network interface driver '%s'\n",
-		    NAME, setting->value);
-		return EINVAL;
+static int init_device(netif_t *netif, devman_handle_t handle)
+{
+	printf("%s: Initializing device '%s'\n", NAME, netif->name);
+	
+	netif->handle = handle;
+	netif->sess = devman_device_connect(EXCHANGE_SERIALIZE, netif->handle,
+	    IPC_FLAG_BLOCKING);
+	if (netif->sess == NULL) {
+		printf("%s: Unable to connect to device\n", NAME);
+		return EREFUSED;
 	}
 	
 	/* Optional network interface layer */
-	setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_NIL, 0);
+	measured_string_t *setting = measured_strings_find(&netif->configuration,
+	    (uint8_t *) CONF_NIL, 0);
 	if (setting) {
-		netif->nil = get_running_module(&net_globals.modules, setting->value);
+		netif->nil = get_running_module(&net_globals.modules,
+		    setting->value);
 		if (!netif->nil) {
-			fprintf(stderr, "%s: Failed to start network interface layer '%s'\n",
+			printf("%s: Unable to connect to network interface layer '%s'\n",
 			    NAME, setting->value);
 			return EINVAL;
@@ -459,143 +314,97 @@
 	
 	/* Mandatory internet layer */
-	setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IL, 0);
-	netif->il = get_running_module(&net_globals.modules, setting->value);
+	setting = measured_strings_find(&netif->configuration,
+	    (uint8_t *) CONF_IL, 0);
+	netif->il = get_running_module(&net_globals.modules,
+	    setting->value);
 	if (!netif->il) {
-		fprintf(stderr, "%s: Failed to start internet layer '%s'\n",
+		printf("%s: Unable to connect to internet layer '%s'\n",
 		    NAME, setting->value);
 		return EINVAL;
 	}
 	
-	/* Hardware configuration */
-	setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IRQ, 0);
-	int irq = setting ? strtol((char *) setting->value, NULL, 10) : 0;
-	
-	setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_IO, 0);
-	uintptr_t io = setting ? strtol((char *) setting->value, NULL, 16) : 0;
-	
-	rc = netif_probe_req(netif->driver->sess, netif->id, irq, (void *) io);
-	if (rc != EOK)
-		return rc;
-	
 	/* Network interface layer startup */
-	services_t internet_service;
+	int rc;
+	services_t nil_service;
 	if (netif->nil) {
-		setting = measured_strings_find(&netif->configuration, (uint8_t *) CONF_MTU, 0);
+		setting = measured_strings_find(&netif->configuration,
+		    (uint8_t *) CONF_MTU, 0);
 		if (!setting)
 			setting = measured_strings_find(&net_globals.configuration,
 			    (uint8_t *) CONF_MTU, 0);
 		
-		int mtu = setting ? strtol((char *) setting->value, NULL, 10) : 0;
-		rc = nil_device_req(netif->nil->sess, netif->id, mtu,
-		    netif->driver->service);
+		int mtu = setting ?
+		    strtol((const char *) setting->value, NULL, 10) : 0;
+		rc = nil_device_req(netif->nil->sess, netif->id,
+		    netif->handle, mtu);
+		if (rc != EOK) {
+			printf("%s: Unable to start network interface layer\n",
+			    NAME);
+			return rc;
+		}
+		
+		nil_service = netif->nil->service;
+	} else
+		nil_service = -1;
+	
+	/* Inter-network layer startup */
+	switch (netif->il->service) {
+	case SERVICE_IP:
+		rc = ip_device_req(netif->il->sess, netif->id, nil_service);
+		if (rc != EOK) {
+			printf("%s: Unable to start internet layer\n", NAME);
+			return rc;
+		}
+		
+		break;
+	default:
+		return ENOENT;
+	}
+	
+	printf("%s: Activating device '%s'\n", NAME, netif->name);
+	return nic_set_state(netif->sess, NIC_STATE_ACTIVE);
+}
+
+static int net_port_ready(devman_handle_t handle)
+{
+	char hwpath[MAX_PATH_LENGTH];
+	int rc = devman_fun_get_path(handle, hwpath, MAX_PATH_LENGTH);
+	if (rc != EOK)
+		return EINVAL;
+	
+	int index = char_map_find(&net_globals.netif_hwpaths,
+	    (uint8_t *) hwpath, 0);
+	if (index == CHAR_MAP_NULL)
+		return ENOENT;
+	
+	netif_t *netif = netifs_get_index(&net_globals.netifs, index);
+	if (netif == NULL)
+		return ENOENT;
+	
+	rc = init_device(netif, handle);
+	if (rc != EOK)
+		return rc;
+	
+	/* Increment module usage */
+	if (netif->nil)
+		netif->nil->usage++;
+	
+	netif->il->usage++;
+	
+	return EOK;
+}
+
+static int net_driver_ready_local(devman_handle_t handle)
+{
+	devman_handle_t *funs;
+	size_t count;
+	int rc = devman_dev_get_functions(handle, &funs, &count);
+	if (rc != EOK)
+		return rc;
+	
+	for (size_t i = 0; i < count; i++) {
+		rc = net_port_ready(funs[i]);
 		if (rc != EOK)
 			return rc;
-		
-		internet_service = netif->nil->service;
-	} else
-		internet_service = netif->driver->service;
-	
-	/* Inter-network layer startup */
-	rc = ip_device_req(netif->il->sess, netif->id, internet_service);
-	if (rc != EOK)
-		return rc;
-	
-	return netif_start_req(netif->driver->sess, netif->id);
-}
-
-/** Read the configuration and start all network interfaces.
- *
- * @return EOK on success.
- * @return EXDEV if there is no available system-unique device identifier.
- * @return EINVAL if any of the network interface names are not configured.
- * @return ENOMEM if there is not enough memory left.
- * @return Other error codes as defined for the read_configuration()
- *         function.
- * @return Other error codes as defined for the read_netif_configuration()
- *         function.
- * @return Other error codes as defined for the start_device() function.
- *
- */
-static int startup(void)
-{
-	const char *conf_files[] = {
-		"lo",
-		"ne2k"
-	};
-	size_t count = sizeof(conf_files) / sizeof(char *);
-	int rc;
-	
-	size_t i;
-	for (i = 0; i < count; i++) {
-		netif_t *netif = (netif_t *) malloc(sizeof(netif_t));
-		if (!netif)
-			return ENOMEM;
-		
-		netif->id = generate_new_device_id();
-		if (!netif->id)
-			return EXDEV;
-		
-		rc = measured_strings_initialize(&netif->configuration);
-		if (rc != EOK)
-			return rc;
-		
-		/* Read configuration files */
-		rc = read_netif_configuration(conf_files[i], netif);
-		if (rc != EOK) {
-			measured_strings_destroy(&netif->configuration, free);
-			free(netif);
-			return rc;
-		}
-		
-		/* Mandatory name */
-		measured_string_t *setting =
-		    measured_strings_find(&netif->configuration, (uint8_t *) CONF_NAME, 0);
-		if (!setting) {
-			fprintf(stderr, "%s: Network interface name is missing\n", NAME);
-			measured_strings_destroy(&netif->configuration, free);
-			free(netif);
-			return EINVAL;
-		}
-		netif->name = setting->value;
-		
-		/* Add to the netifs map */
-		int index = netifs_add(&net_globals.netifs, netif->id, netif);
-		if (index < 0) {
-			measured_strings_destroy(&netif->configuration, free);
-			free(netif);
-			return index;
-		}
-		
-		/*
-		 * Add to the netif names map and start network interfaces
-		 * and needed modules.
-		 */
-		rc = char_map_add(&net_globals.netif_names, netif->name, 0,
-		    index);
-		if (rc != EOK) {
-			measured_strings_destroy(&netif->configuration, free);
-			netifs_exclude_index(&net_globals.netifs, index, free);
-			return rc;
-		}
-		
-		rc = start_device(netif);
-		if (rc != EOK) {
-			printf("%s: Ignoring failed interface %s (%s)\n", NAME,
-			    netif->name, str_error(rc));
-			measured_strings_destroy(&netif->configuration, free);
-			netifs_exclude_index(&net_globals.netifs, index, free);
-			continue;
-		}
-		
-		/* Increment modules' usage */
-		netif->driver->usage++;
-		if (netif->nil)
-			netif->nil->usage++;
-		netif->il->usage++;
-		
-		printf("%s: Network interface started (name: %s, id: %d, driver: %s, "
-		    "nil: %s, il: %s)\n", NAME, netif->name, netif->id,
-		    netif->driver->name, netif->nil ? (char *) netif->nil->name : "[none]",
-		    netif->il->name);
 	}
 	
@@ -618,10 +427,11 @@
  *
  */
-int net_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,
-    size_t *answer_count)
+static int net_message(ipc_callid_t callid, ipc_call_t *call,
+    ipc_call_t *answer, size_t *answer_count)
 {
 	measured_string_t *strings;
 	uint8_t *data;
 	int rc;
+	size_t count;
 	
 	*answer_count = 0;
@@ -636,12 +446,11 @@
 		if (rc != EOK)
 			return rc;
-		net_get_device_conf_req_local(IPC_GET_DEVICE(*call), &strings,
-		    IPC_GET_COUNT(*call), NULL);
-		
-		/* Strings should not contain received data anymore */
-		free(data);
+		
+		net_get_device_conf(IPC_GET_DEVICE(*call), strings,
+		    IPC_GET_COUNT(*call));
 		
 		rc = measured_strings_reply(strings, IPC_GET_COUNT(*call));
 		free(strings);
+		free(data);
 		return rc;
 	case NET_NET_GET_CONF:
@@ -650,17 +459,31 @@
 		if (rc != EOK)
 			return rc;
-		net_get_conf_req_local(&strings, IPC_GET_COUNT(*call), NULL);
-		
-		/* Strings should not contain received data anymore */
-		free(data);
+		
+		net_get_conf(NULL, strings, IPC_GET_COUNT(*call));
 		
 		rc = measured_strings_reply(strings, IPC_GET_COUNT(*call));
 		free(strings);
-		return rc;
-	case NET_NET_STARTUP:
-		return startup();
-	}
-	
-	return ENOTSUP;
+		free(data);
+		return rc;
+	case NET_NET_GET_DEVICES_COUNT:
+		count = (size_t) net_get_devices_count();
+		IPC_SET_ARG1(*answer, count);
+		*answer_count = 1;
+		return EOK;
+	case NET_NET_GET_DEVICES:
+		rc = net_get_devices(&strings, &count);
+		if (rc != EOK)
+			return rc;
+		
+		rc = measured_strings_reply(strings, count);
+		net_free_devices(strings, count);
+		return rc;
+	case NET_NET_DRIVER_READY:
+		rc = net_driver_ready_local(IPC_GET_ARG1(*call));
+		*answer_count = 0;
+		return rc;
+	default:
+		return ENOTSUP;
+	}
 }
 
@@ -684,6 +507,6 @@
 		/* Clear the answer structure */
 		ipc_call_t answer;
-		size_t answer_count;
-		refresh_answer(&answer, &answer_count);
+		size_t count;
+		refresh_answer(&answer, &count);
 		
 		/* Fetch the next message */
@@ -692,5 +515,9 @@
 		
 		/* Process the message */
-		int res = net_module_message(callid, &call, &answer, &answer_count);
+		int res;
+		if (IS_NET_PACKET_MESSAGE(call))
+			res = packet_server_message(callid, &call, &answer, &count);
+		else
+			res = net_message(callid, &call, &answer, &count);
 		
 		/* End if told to either by the message or the processing result */
@@ -699,5 +526,5 @@
 		
 		/* Answer the message */
-		answer_call(callid, res, &answer, answer_count);
+		answer_call(callid, res, &answer, count);
 	}
 }
@@ -705,5 +532,172 @@
 int main(int argc, char *argv[])
 {
-	return net_module_start(net_client_connection);
+	netifs_initialize(&net_globals.netifs);
+	char_map_initialize(&net_globals.netif_hwpaths);
+	modules_initialize(&net_globals.modules);
+	measured_strings_initialize(&net_globals.configuration);
+	async_set_client_connection(net_client_connection);
+	
+	int rc = pm_init();
+	if (rc != EOK) {
+		printf("%s: Unable to initialize packet management\n", NAME);
+		return rc;
+	}
+	
+	rc = packet_server_init();
+	if (rc != EOK) {
+		printf("%s: Unable to initialize packet server\n", NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	rc = read_configuration();
+	if (rc != EOK) {
+		printf("%s: Error reading configuration\n", NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	DIR *config_dir = opendir(CONF_DIR);
+	if (config_dir != NULL) {
+		struct dirent *dir_entry;
+		while ((dir_entry = readdir(config_dir))) {
+			/* Ignore files without the CONF_EXT extension */
+			if ((str_size(dir_entry->d_name) < str_size(CONF_EXT)) ||
+			    (str_cmp(dir_entry->d_name + str_size(dir_entry->d_name) -
+			    str_size(CONF_EXT), CONF_EXT) != 0))
+				continue;
+			
+			
+			netif_t *netif = (netif_t *) malloc(sizeof(netif_t));
+			if (!netif)
+				continue;
+			
+			netif->handle = -1;
+			netif->sess = NULL;
+			
+			netif->id = generate_new_device_id();
+			if (!netif->id) {
+				free(netif);
+				continue;
+			}
+			
+			rc = measured_strings_initialize(&netif->configuration);
+			if (rc != EOK) {
+				free(netif);
+				continue;
+			}
+			
+			rc = read_netif_configuration(dir_entry->d_name, netif);
+			if (rc != EOK) {
+				printf("%s: Error reading configuration %s\n", NAME,
+				    dir_entry->d_name);
+				free(netif);
+				continue;
+			}
+			
+			measured_string_t *name = measured_strings_find(&netif->configuration,
+			    (uint8_t *) CONF_NAME, 0);
+			if (!name) {
+				printf("%s: Network interface name is missing in %s\n",
+				    NAME, dir_entry->d_name);
+				measured_strings_destroy(&netif->configuration, free);
+				free(netif);
+				continue;
+			}
+			
+			netif->name = name->value;
+			
+			/* Mandatory hardware path */
+			measured_string_t *hwpath = measured_strings_find(
+			    &netif->configuration, (const uint8_t *) CONF_HWPATH, 0);
+			if (!hwpath) {
+				printf("%s: Hardware path is missing in %s\n",
+				    NAME, dir_entry->d_name);
+				measured_strings_destroy(&netif->configuration, free);
+				free(netif);
+				continue;
+			}
+			
+			int index = netifs_add(&net_globals.netifs, netif->id, netif);
+			if (index < 0) {
+				measured_strings_destroy(&netif->configuration, free);
+				free(netif);
+				continue;
+			}
+			
+			/*
+			 * Add to the hardware paths map and init network interfaces
+			 * and needed modules.
+			 */
+			rc = char_map_add(&net_globals.netif_hwpaths, hwpath->value, 0, index);
+			if (rc != EOK) {
+				measured_strings_destroy(&netif->configuration, free);
+				netifs_exclude_index(&net_globals.netifs, index, free);
+				continue;
+			}
+		}
+		
+		closedir(config_dir);
+	}
+	
+	rc = add_module(NULL, &net_globals.modules, (uint8_t *) ETHERNET_NAME,
+	    (uint8_t *) ETHERNET_FILENAME, SERVICE_ETHERNET, 0, connect_to_service);
+	if (rc != EOK) {
+		printf("%s: Error adding module '%s'\n", NAME, ETHERNET_NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	rc = add_module(NULL, &net_globals.modules, (uint8_t *) NILDUMMY_NAME,
+	    (uint8_t *) NILDUMMY_FILENAME, SERVICE_NILDUMMY, 0, connect_to_service);
+	if (rc != EOK) {
+		printf("%s: Error adding module '%s'\n", NAME, NILDUMMY_NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	task_id_t task_id = net_spawn((uint8_t *) IP_FILENAME);
+	if (!task_id) {
+		printf("%s: Error spawning IP module\n", NAME);
+		pm_destroy();
+		return EINVAL;
+	}
+	
+	rc = add_module(NULL, &net_globals.modules, (uint8_t *) IP_NAME,
+	    (uint8_t *) IP_FILENAME, SERVICE_IP, task_id, ip_connect_module);
+	if (rc != EOK) {
+		printf("%s: Error adding module '%s'\n", NAME, IP_NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	if (!net_spawn((uint8_t *) "/srv/icmp")) {
+		printf("%s: Error spawning ICMP module\n", NAME);
+		pm_destroy();
+		return EINVAL;
+	}
+	
+	if (!net_spawn((uint8_t *) "/srv/udp")) {
+		printf("%s: Error spawning UDP module\n", NAME);
+		pm_destroy();
+		return EINVAL;
+	}
+	
+	if (!net_spawn((uint8_t *) "/srv/tcp")) {
+		printf("%s: Error spawning TCP module\n", NAME);
+		pm_destroy();
+		return EINVAL;
+	}
+	
+	rc = service_register(SERVICE_NETWORKING);
+	if (rc != EOK) {
+		printf("%s: Error registering service\n", NAME);
+		pm_destroy();
+		return rc;
+	}
+	
+	task_retval(0);
+	async_manager();
+	return 0;
 }
 
Index: uspace/srv/net/net/net.h
===================================================================
--- uspace/srv/net/net/net.h	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/net/net.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2009 Lukas Mejdrech
+ * Copyright (c) 2011 Radim Vansa
  * All rights reserved.
  *
@@ -31,9 +32,4 @@
  */
 
-/** @file
- * Networking subsystem central module.
- *
- */
-
 #ifndef NET_NET_H_
 #define NET_NET_H_
@@ -45,11 +41,7 @@
 #include <adt/module_map.h>
 #include <net/packet.h>
+#include <devman.h>
 
-/** @name Modules definitions
- * @{
- */
-
-#define NE2000_FILENAME  "/srv/ne2000"
-#define NE2000_NAME      "ne2000"
+#define NAME  "net"
 
 #define ETHERNET_FILENAME  "/srv/eth"
@@ -58,7 +50,4 @@
 #define IP_FILENAME  "/srv/ip"
 #define IP_NAME      "ip"
-
-#define LO_FILENAME  "/srv/lo"
-#define LO_NAME      "lo"
 
 #define NILDUMMY_FILENAME  "/srv/nildummy"
@@ -77,5 +66,5 @@
 #define CONF_MTU    "MTU"    /**< Maximum transmission unit configuration label. */
 #define CONF_NAME   "NAME"   /**< Network interface name configuration label. */
-#define CONF_NETIF  "NETIF"  /**< Network interface module name configuration label. */
+#define CONF_HWPATH "HWPATH" /**< Network interface hardware pathname label. */
 #define CONF_NIL    "NIL"    /**< Network interface layer module name configuration label. */
 
@@ -85,4 +74,5 @@
 #define CONF_DIR           "/cfg/net"  /**< Configuration directory. */
 #define CONF_GENERAL_FILE  "general"   /**< General configuration file. */
+#define CONF_EXT           ".nic"      /**< Extension for NIC's configuration files. */
 
 /** Configuration settings.
@@ -98,13 +88,17 @@
  */
 typedef struct {
-	measured_strings_t configuration;  /**< Configuration. */
+	/** System-unique network interface name. */
+	uint8_t *name;
+	/** System-unique network interface identifier. */
+	nic_device_id_t id;
+	/** Configuration. */
+	measured_strings_t configuration;
 	
 	/** Serving network interface driver module index. */
-	module_t *driver;
+	devman_handle_t handle;  /**< Handle for devman */
+	async_sess_t *sess;      /**< Driver session. */
 	
-	device_id_t id;  /**< System-unique network interface identifier. */
-	module_t *il;    /**< Serving internet layer module index. */
-	uint8_t *name;   /**< System-unique network interface name. */
-	module_t *nil;   /**< Serving link layer module index. */
+	module_t *nil;  /**< Serving link layer module index. */
+	module_t *il;   /**< Serving internet layer module index. */
 } netif_t;
 
@@ -124,6 +118,6 @@
 	modules_t modules;                 /**< Available modules. */
 	
-	/** Network interface structure indices by names. */
-	char_map_t netif_names;
+	/** Network interface structure indices by hardware path. */
+	char_map_t netif_hwpaths;
 	
 	/** Present network interfaces. */
@@ -131,10 +125,4 @@
 } net_globals_t;
 
-extern int add_configuration(measured_strings_t *, const uint8_t *,
-    const uint8_t *);
-extern int net_module_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, size_t *);
-extern int net_initialize_build(async_client_conn_t);
-extern int net_message(ipc_callid_t, ipc_call_t *, ipc_call_t *, size_t *);
-
 #endif
 
Index: uspace/srv/net/net/net_standalone.c
===================================================================
--- uspace/srv/net/net/net_standalone.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,110 +1,0 @@
-/*
- * 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 net
- * @{
- */
-
-/** @file
- * Wrapper for the standalone networking module.
- */
-
-#include "net.h"
-
-#include <str.h>
-#include <adt/measured_strings.h>
-#include <adt/module_map.h>
-#include <ipc/net.h>
-#include <errno.h>
-
-#include <ip_interface.h>
-#include <packet_server.h>
-
-/** Networking module global data. */
-extern net_globals_t net_globals;
-
-/** Initialize the networking module for the chosen subsystem build type.
- *
- *  @param[in] client_connection The client connection processing function.
- *                               The module skeleton propagates its own one.
- *
- *  @return EOK on success.
- *  @return ENOMEM if there is not enough memory left.
- *
- */
-int net_initialize_build(async_client_conn_t client_connection)
-{
-	int rc;
-	
-	task_id_t task_id = net_spawn((uint8_t *) "/srv/ip");
-	if (!task_id)
-		return EINVAL;
-	
-	rc = add_module(NULL, &net_globals.modules, (uint8_t *) IP_NAME,
-	    (uint8_t *) IP_FILENAME, SERVICE_IP, task_id, ip_connect_module);
-	if (rc != EOK)
-		return rc;
-	
-	if (!net_spawn((uint8_t *) "/srv/icmp"))
-		return EINVAL;
-	
-	if (!net_spawn((uint8_t *) "/srv/udp"))
-		return EINVAL;
-	
-	if (!net_spawn((uint8_t *) "/srv/tcp"))
-		return EINVAL;
-	
-	return EOK;
-}
-
-/** Process the module message.
- *
- * Distribute the message to the right module.
- *
- * @param[in]  callid       The message identifier.
- * @param[in]  call         The message parameters.
- * @param[out] answer       The message answer parameters.
- * @param[out] answer_count The last parameter for the actual answer in
- *                          the answer parameter.
- *
- * @return EOK on success.
- * @return ENOTSUP if the message is not known.
- * @return Other error codes.
- *
- */
-int net_module_message(ipc_callid_t callid, ipc_call_t *call,
-    ipc_call_t *answer, size_t *count)
-{
-	if (IS_NET_PACKET_MESSAGE(*call))
-		return packet_server_message(callid, call, answer, count);
-	
-	return net_message(callid, call, answer, count);
-}
-
-/** @}
- */
Index: uspace/srv/net/net/packet_server.c
===================================================================
--- uspace/srv/net/net/packet_server.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
+++ uspace/srv/net/net/packet_server.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -0,0 +1,403 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * Copyright (c) 2011 Radim Vansa
+ * 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 libpacket
+ *  @{
+ */
+
+/** @file
+ * Packet server implementation.
+ */
+
+#include <align.h>
+#include <assert.h>
+#include <async.h>
+#include <errno.h>
+#include <str_error.h>
+#include <stdio.h>
+#include <fibril_synch.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <ipc/packet.h>
+#include <ipc/net.h>
+#include <net/packet.h>
+#include <net/packet_header.h>
+
+#include "packet_server.h"
+
+#define PACKET_SERVER_PROFILE 1
+
+/** Number of queues cacheing the unused packets */
+#define FREE_QUEUES_COUNT	7
+/** Maximum number of packets in each queue */
+#define FREE_QUEUE_MAX_LENGTH	16
+
+/** The default address length reserved for new packets. */
+#define DEFAULT_ADDR_LEN	32
+
+/** The default prefix reserved for new packets. */
+#define DEFAULT_PREFIX		64
+
+/** The default suffix reserved for new packets. */
+#define DEFAULT_SUFFIX		64
+
+/** The queue with unused packets */
+typedef struct packet_queue {
+	packet_t *first;	/**< First packet in the queue */
+	size_t packet_size; /**< Maximal size of the packets in this queue */
+	int count;			/**< Length of the queue */
+} packet_queue_t;
+
+/** Packet server global data. */
+static struct {
+	/** Safety lock. */
+	fibril_mutex_t lock;
+	/** Free packet queues. */
+	packet_queue_t free_queues[FREE_QUEUES_COUNT];
+	
+	/** Total packets allocated. */
+	packet_id_t next_id;
+} ps_globals = {
+	.lock = FIBRIL_MUTEX_INITIALIZER(ps_globals.lock),
+	.free_queues = {
+		{ NULL, PAGE_SIZE, 0},
+		{ NULL, PAGE_SIZE * 2, 0},
+		{ NULL, PAGE_SIZE * 4, 0},
+		{ NULL, PAGE_SIZE * 8, 0},
+		{ NULL, PAGE_SIZE * 16, 0},
+		{ NULL, PAGE_SIZE * 32, 0},
+		{ NULL, PAGE_SIZE * 64, 0},
+	},
+	.next_id = 1
+};
+
+/** Clears and initializes the packet according to the given dimensions.
+ *
+ * @param[in] packet	The packet to be initialized.
+ * @param[in] addr_len	The source and destination addresses maximal length in
+ *			bytes.
+ * @param[in] max_prefix The maximal prefix length in bytes.
+ * @param[in] max_content The maximal content length in bytes.
+ * @param[in] max_suffix The maximal suffix length in bytes.
+ */
+static void packet_init(packet_t *packet,
+	size_t addr_len, size_t max_prefix, size_t max_content, size_t max_suffix)
+{
+	/* Clear the packet content */
+	bzero(((void *) packet) + sizeof(packet_t),
+	    packet->length - sizeof(packet_t));
+	
+	/* Clear the packet header */
+	packet->order = 0;
+	packet->metric = 0;
+	packet->previous = 0;
+	packet->next = 0;
+	packet->offload_info = 0;
+	packet->offload_mask = 0;
+	packet->addr_len = 0;
+	packet->src_addr = sizeof(packet_t);
+	packet->dest_addr = packet->src_addr + addr_len;
+	packet->max_prefix = max_prefix;
+	packet->max_content = max_content;
+	packet->data_start = packet->dest_addr + addr_len + packet->max_prefix;
+	packet->data_end = packet->data_start;
+}
+
+/**
+ * Releases the memory allocated for the packet
+ *
+ * @param[in] packet Pointer to the memory where the packet was allocated
+ */
+static void packet_dealloc(packet_t *packet)
+{
+	pm_remove(packet);
+	munmap(packet, packet->length);
+}
+
+/** Creates a new packet of dimensions at least as given.
+ *
+ * @param[in] length	The total length of the packet, including the header,
+ *			the addresses and the data of the packet.
+ * @param[in] addr_len	The source and destination addresses maximal length in
+ *			bytes.
+ * @param[in] max_prefix The maximal prefix length in bytes.
+ * @param[in] max_content The maximal content length in bytes.
+ * @param[in] max_suffix The maximal suffix length in bytes.
+ * @return		The packet of dimensions at least as given.
+ * @return		NULL if there is not enough memory left.
+ */
+static packet_t *packet_alloc(size_t length, size_t addr_len,
+	size_t max_prefix, size_t max_content, size_t max_suffix)
+{
+	packet_t *packet;
+	int rc;
+
+	/* Global lock is locked */
+	assert(fibril_mutex_is_locked(&ps_globals.lock));
+	/* The length is some multiple of PAGE_SIZE */
+	assert(!(length & (PAGE_SIZE - 1)));
+
+	packet = (packet_t *) mmap(NULL, length, PROTO_READ | PROTO_WRITE,
+		MAP_SHARED | MAP_ANONYMOUS, 0, 0);
+	if (packet == MAP_FAILED)
+		return NULL;
+	
+	/* Using 32bit packet_id the id could overflow */
+	packet_id_t pid;
+	do {
+		pid = ps_globals.next_id;
+		ps_globals.next_id++;
+	} while (!pid || pm_find(pid));
+	packet->packet_id = pid;
+
+	packet->length = length;
+	packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
+	packet->magic_value = PACKET_MAGIC_VALUE;
+	rc = pm_add(packet);
+	if (rc != EOK) {
+		packet_dealloc(packet);
+		return NULL;
+	}
+	
+	return packet;
+}
+
+/** Return the packet of dimensions at least as given.
+ *
+ * Try to reuse free packets first.
+ * Create a new packet aligned to the memory page size if none available.
+ * Lock the global data during its processing.
+ *
+ * @param[in] addr_len	The source and destination addresses maximal length in
+ *			bytes.
+ * @param[in] max_prefix The maximal prefix length in bytes.
+ * @param[in] max_content The maximal content length in bytes.
+ * @param[in] max_suffix The maximal suffix length in bytes.
+ * @return		The packet of dimensions at least as given.
+ * @return		NULL if there is not enough memory left.
+ */
+static packet_t *packet_get_local(size_t addr_len,
+	size_t max_prefix, size_t max_content, size_t max_suffix)
+{
+	size_t length = ALIGN_UP(sizeof(packet_t) + 2 * addr_len
+		+ max_prefix + max_content + max_suffix, PAGE_SIZE);
+	
+	if (length > PACKET_MAX_LENGTH)
+		return NULL;
+
+	fibril_mutex_lock(&ps_globals.lock);
+	
+	packet_t *packet;
+	unsigned int index;
+	
+	for (index = 0; index < FREE_QUEUES_COUNT; index++) {
+		if ((length > ps_globals.free_queues[index].packet_size) &&
+			(index < FREE_QUEUES_COUNT - 1))
+			continue;
+		
+		packet = ps_globals.free_queues[index].first;
+		while (packet_is_valid(packet) && (packet->length < length))
+			packet = pm_find(packet->next);
+		
+		if (packet_is_valid(packet)) {
+			ps_globals.free_queues[index].count--;
+			if (packet == ps_globals.free_queues[index].first) {
+				ps_globals.free_queues[index].first = pq_detach(packet);
+			} else {
+				pq_detach(packet);
+			}
+			
+			packet_init(packet, addr_len, max_prefix, max_content, max_suffix);
+			fibril_mutex_unlock(&ps_globals.lock);
+			
+			return packet;
+		}
+	}
+	
+	packet = packet_alloc(length, addr_len,
+		max_prefix, max_content, max_suffix);
+	
+	fibril_mutex_unlock(&ps_globals.lock);
+	
+	return packet;
+}
+
+/** Release the packet and returns it to the appropriate free packet queue.
+ *
+ * @param[in] packet	The packet to be released.
+ *
+ */
+static void packet_release(packet_t *packet)
+{
+	int index;
+	int result;
+
+	assert(fibril_mutex_is_locked(&ps_globals.lock));
+
+	for (index = 0; (index < FREE_QUEUES_COUNT - 1) &&
+	    (packet->length > ps_globals.free_queues[index].packet_size); index++) {
+		;
+	}
+	
+	ps_globals.free_queues[index].count++;
+	result = pq_add(&ps_globals.free_queues[index].first, packet,
+		packet->length,	packet->length);
+	assert(result == EOK);
+}
+
+/** Releases the packet queue.
+ *
+ * @param[in] packet_id	The first packet identifier.
+ * @return		EOK on success.
+ * @return		ENOENT if there is no such packet.
+ */
+static int packet_release_wrapper(packet_id_t packet_id)
+{
+	packet_t *packet;
+
+	packet = pm_find(packet_id);
+	if (!packet_is_valid(packet))
+		return ENOENT;
+
+	fibril_mutex_lock(&ps_globals.lock);
+	pq_destroy(packet, packet_release);
+	fibril_mutex_unlock(&ps_globals.lock);
+
+	return EOK;
+}
+
+/** Shares the packet memory block.
+ * @param[in] packet	The packet to be shared.
+ * @return		EOK on success.
+ * @return		EINVAL if the packet is not valid.
+ * @return		EINVAL if the calling module does not accept the memory.
+ * @return		ENOMEM if the desired and actual sizes differ.
+ * @return		Other error codes as defined for the
+ *			async_share_in_finalize() function.
+ */
+static int packet_reply(packet_t *packet)
+{
+	ipc_callid_t callid;
+	size_t size;
+
+	if (!packet_is_valid(packet))
+		return EINVAL;
+
+	if (!async_share_in_receive(&callid, &size)) {
+		async_answer_0(callid, EINVAL);
+		return EINVAL;
+	}
+
+	if (size != packet->length) {
+		async_answer_0(callid, ENOMEM);
+		return ENOMEM;
+	}
+	
+	return async_share_in_finalize(callid, packet,
+	    PROTO_READ | PROTO_WRITE);
+}
+
+/** Processes the packet server message.
+ *
+ * @param[in] callid	The message identifier.
+ * @param[in] call	The message parameters.
+ * @param[out] answer	The message answer parameters.
+ * @param[out] answer_count The last parameter for the actual answer in the
+ *			answer parameter.
+ * @return		EOK on success.
+ * @return		ENOMEM if there is not enough memory left.
+ * @return		ENOENT if there is no such packet as in the packet
+ *			message parameter.
+ * @return		ENOTSUP if the message is not known.
+ * @return		Other error codes as defined for the
+ *			packet_release_wrapper() function.
+ */
+int packet_server_message(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,
+    size_t *answer_count)
+{
+	packet_t *packet;
+	
+	if (!IPC_GET_IMETHOD(*call))
+		return EOK;
+	
+	*answer_count = 0;
+	switch (IPC_GET_IMETHOD(*call)) {
+	case NET_PACKET_CREATE_1:
+		packet = packet_get_local(DEFAULT_ADDR_LEN, DEFAULT_PREFIX,
+			IPC_GET_CONTENT(*call), DEFAULT_SUFFIX);
+		if (!packet)
+			return ENOMEM;
+		*answer_count = 2;
+		IPC_SET_ARG1(*answer, (sysarg_t) packet->packet_id);
+		IPC_SET_ARG2(*answer, (sysarg_t) packet->length);
+		return EOK;
+	
+	case NET_PACKET_CREATE_4:
+		packet = packet_get_local(
+			((DEFAULT_ADDR_LEN < IPC_GET_ADDR_LEN(*call)) ?
+		    IPC_GET_ADDR_LEN(*call) : DEFAULT_ADDR_LEN),
+		    DEFAULT_PREFIX + IPC_GET_PREFIX(*call),
+		    IPC_GET_CONTENT(*call),
+		    DEFAULT_SUFFIX + IPC_GET_SUFFIX(*call));
+		if (!packet)
+			return ENOMEM;
+		*answer_count = 2;
+		IPC_SET_ARG1(*answer, (sysarg_t) packet->packet_id);
+		IPC_SET_ARG2(*answer, (sysarg_t) packet->length);
+		return EOK;
+	
+	case NET_PACKET_GET:
+		packet = pm_find(IPC_GET_ID(*call));
+		if (!packet_is_valid(packet)) {
+			return ENOENT;
+		}
+		return packet_reply(packet);
+	
+	case NET_PACKET_GET_SIZE:
+		packet = pm_find(IPC_GET_ID(*call));
+		if (!packet_is_valid(packet))
+			return ENOENT;
+		IPC_SET_ARG1(*answer, (sysarg_t) packet->length);
+		*answer_count = 1;
+		return EOK;
+	
+	case NET_PACKET_RELEASE:
+		return packet_release_wrapper(IPC_GET_ID(*call));
+	}
+	
+	return ENOTSUP;
+}
+
+int packet_server_init()
+{
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/srv/net/net/packet_server.h
===================================================================
--- uspace/srv/net/net/packet_server.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
+++ uspace/srv/net/net/packet_server.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2009 Lukas Mejdrech
+ * Copyright (c) 2011 Radim Vansa
+ * 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 libpacket
+ * @{
+ */
+
+/** @file
+ * Packet server.
+ * The hosting module has to be compiled with both the packet.c and the
+ * packet_server.c source files. To function correctly, initialization of the
+ * packet map by the pm_init() function has to happen at the first place. Then
+ * the packet messages have to be processed by the packet_server_message()
+ * function. The packet map should be released by the pm_destroy() function
+ * during the module termination.
+ * @see IS_NET_PACKET_MESSAGE()
+ */
+
+#ifndef NET_PACKET_SERVER_H_
+#define NET_PACKET_SERVER_H_
+
+#include <ipc/common.h>
+
+extern int packet_server_init(void);
+extern int packet_server_message(ipc_callid_t, ipc_call_t *, ipc_call_t *,
+    size_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/srv/net/netif/lo/Makefile
===================================================================
--- uspace/srv/net/netif/lo/Makefile	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,46 +1,0 @@
-#
-# Copyright (c) 2005 Martin Decky
-# Copyright (c) 2007 Jakub Jermar
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-#   notice, this list of conditions and the following disclaimer.
-# - Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in the
-#   documentation and/or other materials provided with the distribution.
-# - The name of the author may not be used to endorse or promote products
-#   derived from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
-# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
-USPACE_PREFIX = ../../../..
-ROOT_PATH = $(USPACE_PREFIX)/..
-LIBS = $(LIBNET_PREFIX)/libnet.a
-EXTRA_CFLAGS = -I$(LIBNET_PREFIX)/include
-
-COMMON_MAKEFILE = $(ROOT_PATH)/Makefile.common
-CONFIG_MAKEFILE = $(ROOT_PATH)/Makefile.config
-
--include $(COMMON_MAKEFILE)
--include $(CONFIG_MAKEFILE)
-
-BINARY = lo
-
-SOURCES = \
-	lo.c
-
-include $(USPACE_PREFIX)/Makefile.common
Index: uspace/srv/net/netif/lo/lo.c
===================================================================
--- uspace/srv/net/netif/lo/lo.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ 	(revision )
@@ -1,231 +1,0 @@
-/*
- * 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 lo
- * @{
- */
-
-/** @file
- * Loopback network interface implementation.
- */
-
-#include <async.h>
-#include <errno.h>
-#include <stdio.h>
-#include <str.h>
-#include <ns.h>
-#include <ipc/services.h>
-#include <ipc/nil.h>
-#include <net/modules.h>
-#include <adt/measured_strings.h>
-#include <packet_client.h>
-#include <net/device.h>
-#include <netif_skel.h>
-#include <nil_remote.h>
-
-/** Default address length. */
-#define DEFAULT_ADDR_LEN  6
-
-/** Loopback module name. */
-#define NAME  "lo"
-
-static uint8_t default_addr[DEFAULT_ADDR_LEN] =
-    {0, 0, 0, 0, 0, 0};
-
-int netif_specific_message(ipc_callid_t callid, ipc_call_t *call,
-    ipc_call_t *answer, size_t *count)
-{
-	return ENOTSUP;
-}
-
-int netif_get_addr_message(device_id_t device_id, measured_string_t *address)
-{
-	if (!address)
-		return EBADMEM;
-	
-	address->value = default_addr;
-	address->length = DEFAULT_ADDR_LEN;
-	
-	return EOK;
-}
-
-int netif_get_device_stats(device_id_t device_id, device_stats_t *stats)
-{
-	if (!stats)
-		return EBADMEM;
-	
-	netif_device_t *device;
-	int rc = find_device(device_id, &device);
-	if (rc != EOK)
-		return rc;
-	
-	memcpy(stats, (device_stats_t *) device->specific,
-	    sizeof(device_stats_t));
-	
-	return EOK;
-}
-
-/** Change the loopback state.
- *
- * @param[in] device The device structure.
- * @param[in] state  The new device state.
- *
- * @return New state if changed.
- * @return EOK otherwise.
- *
- */
-static void change_state_message(netif_device_t *device, device_state_t state)
-{
-	if (device->state != state) {
-		device->state = state;
-		
-		const char *desc;
-		switch (state) {
-		case NETIF_ACTIVE:
-			desc = "active";
-			break;
-		case NETIF_STOPPED:
-			desc = "stopped";
-			break;
-		default:
-			desc = "unknown";
-		}
-		
-		printf("%s: State changed to %s\n", NAME, desc);
-	}
-}
-
-/** Create and return the loopback network interface structure.
- *
- * @param[in]  device_id New devce identifier.
- * @param[out] device    Device structure.
- *
- * @return EOK on success.
- * @return EXDEV if one loopback network interface already exists.
- * @return ENOMEM if there is not enough memory left.
- *
- */
-static int lo_create(device_id_t device_id, netif_device_t **device)
-{
-	if (netif_device_map_count(&netif_globals.device_map) > 0)
-		return EXDEV;
-	
-	*device = (netif_device_t *) malloc(sizeof(netif_device_t));
-	if (!*device)
-		return ENOMEM;
-	
-	(*device)->specific = (device_stats_t *) malloc(sizeof(device_stats_t));
-	if (!(*device)->specific) {
-		free(*device);
-		return ENOMEM;
-	}
-	
-	null_device_stats((device_stats_t *) (*device)->specific);
-	(*device)->device_id = device_id;
-	(*device)->state = NETIF_STOPPED;
-	int index = netif_device_map_add(&netif_globals.device_map,
-	    (*device)->device_id, *device);
-	
-	if (index < 0) {
-		free(*device);
-		free((*device)->specific);
-		*device = NULL;
-		return index;
-	}
-	
-	return EOK;
-}
-
-int netif_initialize(void)
-{
-	return service_register(SERVICE_LO);
-}
-
-int netif_probe_message(device_id_t device_id, int irq, void *io)
-{
-	/* Create a new device */
-	netif_device_t *device;
-	int rc = lo_create(device_id, &device);
-	if (rc != EOK)
-		return rc;
-	
-	printf("%s: Device created (id: %d)\n", NAME, device->device_id);
-	return EOK;
-}
-
-int netif_send_message(device_id_t device_id, packet_t *packet, services_t sender)
-{
-	netif_device_t *device;
-	int rc = find_device(device_id, &device);
-	if (rc != EOK)
-		return EOK;
-	
-	if (device->state != NETIF_ACTIVE) {
-		netif_pq_release(packet_get_id(packet));
-		return EFORWARD;
-	}
-	
-	packet_t *next = packet;
-	do {
-		((device_stats_t *) device->specific)->send_packets++;
-		((device_stats_t *) device->specific)->receive_packets++;
-		size_t length = packet_get_data_length(next);
-		((device_stats_t *) device->specific)->send_bytes += length;
-		((device_stats_t *) device->specific)->receive_bytes += length;
-		next = pq_next(next);
-	} while (next);
-	
-	async_sess_t *nil_sess = netif_globals.nil_sess;
-	fibril_rwlock_write_unlock(&netif_globals.lock);
-	
-	nil_received_msg(nil_sess, device_id, packet, sender);
-	
-	fibril_rwlock_write_lock(&netif_globals.lock);
-	return EOK;
-}
-
-int netif_start_message(netif_device_t *device)
-{
-	change_state_message(device, NETIF_ACTIVE);
-	return device->state;
-}
-
-int netif_stop_message(netif_device_t *device)
-{
-	change_state_message(device, NETIF_STOPPED);
-	return device->state;
-}
-
-int main(int argc, char *argv[])
-{
-	/* Start the module */
-	return netif_module_start();
-}
-
-/** @}
- */
Index: uspace/srv/net/nil/eth/eth.c
===================================================================
--- uspace/srv/net/nil/eth/eth.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/nil/eth/eth.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2009 Lukas Mejdrech
+ * Copyright (c) 2011 Radim Vansa
  * All rights reserved.
  *
@@ -36,4 +37,5 @@
  */
 
+#include <assert.h>
 #include <async.h>
 #include <malloc.h>
@@ -52,5 +54,4 @@
 #include <protocol_map.h>
 #include <net/device.h>
-#include <netif_remote.h>
 #include <net_interface.h>
 #include <il_remote.h>
@@ -58,4 +59,5 @@
 #include <packet_client.h>
 #include <packet_remote.h>
+#include <device/nic.h>
 #include <nil_skel.h>
 #include "eth.h"
@@ -167,5 +169,5 @@
 INT_MAP_IMPLEMENT(eth_protos, eth_proto_t);
 
-int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
+int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state)
 {
 	int index;
@@ -195,12 +197,8 @@
 	fibril_rwlock_write_lock(&eth_globals.devices_lock);
 	fibril_rwlock_write_lock(&eth_globals.protos_lock);
+	
 	eth_globals.net_sess = sess;
-
-	eth_globals.broadcast_addr =
-	    measured_string_create_bulk((uint8_t *) "\xFF\xFF\xFF\xFF\xFF\xFF", ETH_ADDR);
-	if (!eth_globals.broadcast_addr) {
-		rc = ENOMEM;
-		goto out;
-	}
+	memcpy(eth_globals.broadcast_addr, "\xFF\xFF\xFF\xFF\xFF\xFF",
+			ETH_ADDR);
 
 	rc = eth_devices_initialize(&eth_globals.devices);
@@ -215,4 +213,5 @@
 		eth_devices_destroy(&eth_globals.devices, free);
 	}
+	
 out:
 	fibril_rwlock_write_unlock(&eth_globals.protos_lock);
@@ -222,59 +221,18 @@
 }
 
-/** Process IPC messages from the registered device driver modules in an
- * infinite loop.
- *
- * @param[in]     iid   Message identifier.
- * @param[in,out] icall Message parameters.
- * @param[in]     arg   Local argument.
- *
- */
-static void eth_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
-{
-	packet_t *packet;
-	int rc;
-
-	while (true) {
-		switch (IPC_GET_IMETHOD(*icall)) {
-		case NET_NIL_DEVICE_STATE:
-			nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
-			    IPC_GET_STATE(*icall));
-			async_answer_0(iid, EOK);
-			break;
-		case NET_NIL_RECEIVED:
-			rc = packet_translate_remote(eth_globals.net_sess,
-			    &packet, IPC_GET_PACKET(*icall));
-			if (rc == EOK)
-				rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
-				    packet, 0);
-			
-			async_answer_0(iid, (sysarg_t) rc);
-			break;
-		default:
-			async_answer_0(iid, (sysarg_t) ENOTSUP);
-		}
-		
-		iid = async_get_call(icall);
-	}
-}
-
-/** Registers new device or updates the MTU of an existing one.
- *
- * Determines the device local hardware address.
- *
- * @param[in] device_id	The new device identifier.
- * @param[in] service	The device driver service.
- * @param[in] mtu	The device maximum transmission unit.
- * @return		EOK on success.
- * @return		EEXIST if the device with the different service exists.
- * @return		ENOMEM if there is not enough memory left.
- * @return		Other error codes as defined for the
- *			net_get_device_conf_req() function.
- * @return		Other error codes as defined for the
- *			netif_bind_service() function.
- * @return		Other error codes as defined for the
- *			netif_get_addr_req() function.
- */
-static int eth_device_message(device_id_t device_id, services_t service,
+/** Register new device or updates the MTU of an existing one.
+ *
+ * Determine the device local hardware address.
+ *
+ * @param[in] device_id New device identifier.
+ * @param[in] handle    Device driver handle.
+ * @param[in] mtu       Device maximum transmission unit.
+ *
+ * @return EOK on success.
+ * @return EEXIST if the device with the different service exists.
+ * @return ENOMEM if there is not enough memory left.
+ *
+ */
+static int eth_device_message(nic_device_id_t device_id, devman_handle_t handle,
     size_t mtu)
 {
@@ -301,5 +259,5 @@
 	device = eth_devices_find(&eth_globals.devices, device_id);
 	if (device) {
-		if (device->service != service) {
+		if (device->handle != handle) {
 			printf("Device %d already exists\n", device->device_id);
 			fibril_rwlock_write_unlock(&eth_globals.devices_lock);
@@ -340,5 +298,5 @@
 
 	device->device_id = device_id;
-	device->service = service;
+	device->handle = handle;
 	device->flags = 0;
 	if ((mtu > 0) && (mtu <= ETH_MAX_TAGGED_CONTENT(device->flags)))
@@ -377,6 +335,6 @@
 	
 	/* Bind the device driver */
-	device->sess = netif_bind_service(device->service, device->device_id,
-	    SERVICE_ETHERNET, eth_receiver);
+	device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,
+	    IPC_FLAG_BLOCKING);
 	if (device->sess == NULL) {
 		fibril_rwlock_write_unlock(&eth_globals.devices_lock);
@@ -385,7 +343,8 @@
 	}
 	
+	nic_connect_to_nil(device->sess, SERVICE_ETHERNET, device_id);
+	
 	/* Get hardware address */
-	rc = netif_get_addr_req(device->sess, device->device_id, &device->addr,
-	    &device->addr_data);
+	rc = nic_get_address(device->sess, &device->addr);
 	if (rc != EOK) {
 		fibril_rwlock_write_unlock(&eth_globals.devices_lock);
@@ -399,16 +358,12 @@
 	if (index < 0) {
 		fibril_rwlock_write_unlock(&eth_globals.devices_lock);
-		free(device->addr);
-		free(device->addr_data);
 		free(device);
 		return index;
 	}
 	
-	printf("%s: Device registered (id: %d, service: %d: mtu: %zu, "
-	    "mac: %02x:%02x:%02x:%02x:%02x:%02x, flags: 0x%x)\n",
-	    NAME, device->device_id, device->service, device->mtu,
-	    device->addr_data[0], device->addr_data[1],
-	    device->addr_data[2], device->addr_data[3],
-	    device->addr_data[4], device->addr_data[5], device->flags);
+	printf("%s: Device registered (id: %d, handle: %zu: mtu: %zu, "
+	    "mac: " PRIMAC ", flags: 0x%x)\n", NAME,
+	    device->device_id, device->handle, device->mtu,
+	    ARGSMAC(device->addr.address), device->flags);
 
 	fibril_rwlock_write_unlock(&eth_globals.devices_lock);
@@ -456,5 +411,5 @@
 		fcs = (eth_fcs_t *) data + length - sizeof(eth_fcs_t);
 		length -= sizeof(eth_fcs_t);
-	} else if(type <= ETH_MAX_CONTENT) {
+	} else if (type <= ETH_MAX_CONTENT) {
 		/* Translate "LSAP" values */
 		if ((header->lsap.dsap == ETH_LSAP_GLSAP) &&
@@ -462,5 +417,5 @@
 			/* Raw packet -- discard */
 			return NULL;
-		} else if((header->lsap.dsap == ETH_LSAP_SNAP) &&
+		} else if ((header->lsap.dsap == ETH_LSAP_SNAP) &&
 		    (header->lsap.ssap == ETH_LSAP_SNAP)) {
 			/*
@@ -469,12 +424,10 @@
 			 */
 			type = ntohs(header->snap.ethertype);
-			prefix = sizeof(eth_header_t) +
-			    sizeof(eth_header_lsap_t) +
+			prefix = sizeof(eth_header_t) + sizeof(eth_header_lsap_t) +
 			    sizeof(eth_header_snap_t);
 		} else {
 			/* IEEE 802.3 + 802.2 LSAP */
 			type = lsap_map(header->lsap.dsap);
-			prefix = sizeof(eth_header_t) +
-			    sizeof(eth_header_lsap_t);
+			prefix = sizeof(eth_header_t) + sizeof(eth_header_lsap_t);
 		}
 
@@ -506,6 +459,5 @@
 }
 
-int nil_received_msg_local(device_id_t device_id, packet_t *packet,
-    services_t target)
+int nil_received_msg_local(nic_device_id_t device_id, packet_t *packet)
 {
 	eth_proto_t *proto;
@@ -523,6 +475,6 @@
 	flags = device->flags;
 	fibril_rwlock_read_unlock(&eth_globals.devices_lock);
-	
 	fibril_rwlock_read_lock(&eth_globals.protos_lock);
+	
 	do {
 		next = pq_detach(packet);
@@ -537,5 +489,5 @@
 		}
 		packet = next;
-	} while(packet);
+	} while (packet);
 
 	fibril_rwlock_read_unlock(&eth_globals.protos_lock);
@@ -554,5 +506,5 @@
  * @return		ENOENT if there is no such device.
  */
-static int eth_packet_space_message(device_id_t device_id, size_t *addr_len,
+static int eth_packet_space_message(nic_device_id_t device_id, size_t *addr_len,
     size_t *prefix, size_t *content, size_t *suffix)
 {
@@ -579,24 +531,22 @@
 }
 
-/** Returns the device hardware address.
+/** Send the device hardware address.
  *
  * @param[in] device_id	The device identifier.
  * @param[in] type	Type of the desired address.
- * @param[out] address	The device hardware address.
  * @return		EOK on success.
  * @return		EBADMEM if the address parameter is NULL.
  * @return		ENOENT if there no such device.
  */
-static int eth_addr_message(device_id_t device_id, eth_addr_type_t type,
-    measured_string_t **address)
-{
-	eth_device_t *device;
-
-	if (!address)
-		return EBADMEM;
-
-	if (type == ETH_BROADCAST_ADDR) {
-		*address = eth_globals.broadcast_addr;
-	} else {
+static int eth_addr_message(nic_device_id_t device_id, eth_addr_type_t type)
+{
+	eth_device_t *device = NULL;
+	uint8_t *address;
+	size_t max_len;
+	ipc_callid_t callid;
+	
+	if (type == ETH_BROADCAST_ADDR)
+		address = eth_globals.broadcast_addr;
+	else {
 		fibril_rwlock_read_lock(&eth_globals.devices_lock);
 		device = eth_devices_find(&eth_globals.devices, device_id);
@@ -605,9 +555,30 @@
 			return ENOENT;
 		}
-		*address = device->addr;
+		
+		address = (uint8_t *) &device->addr.address;
+	}
+	
+	int rc = EOK;
+	if (!async_data_read_receive(&callid, &max_len)) {
+		rc = EREFUSED;
+		goto end;
+	}
+	
+	if (max_len < ETH_ADDR) {
+		async_data_read_finalize(callid, NULL, 0);
+		rc = ELIMIT;
+		goto end;
+	}
+	
+	rc = async_data_read_finalize(callid, address, ETH_ADDR);
+	if (rc != EOK)
+		goto end;
+	
+end:
+	
+	if (type == ETH_LOCAL_ADDR)
 		fibril_rwlock_read_unlock(&eth_globals.devices_lock);
-	}
-	
-	return (*address) ? EOK : ENOENT;
+	
+	return rc;
 }
 
@@ -659,5 +630,5 @@
 	}
 	
-	printf("%s: Protocol registered (protocol: %d, service: %d)\n",
+	printf("%s: Protocol registered (protocol: %d, service: %#x)\n",
 	    NAME, proto->protocol, proto->service);
 	
@@ -697,6 +668,14 @@
 	if (i < 0)
 		return i;
+	
 	if (i != ETH_ADDR)
 		return EINVAL;
+	
+	for (i = 0; i < ETH_ADDR; i++) {
+		if (src[i]) {
+			src_addr = src;
+			break;
+		}
+	}
 
 	length = packet_get_data_length(packet);
@@ -722,5 +701,5 @@
 		memcpy(header_dix->destination_address, dest, ETH_ADDR);
 		src = &header_dix->destination_address[0];
-	} else if(IS_8023_2_LSAP(flags)) {
+	} else if (IS_8023_2_LSAP(flags)) {
 		header_lsap = PACKET_PREFIX(packet, eth_header_lsap_t);
 		if (!header_lsap)
@@ -735,5 +714,5 @@
 		memcpy(header_lsap->header.destination_address, dest, ETH_ADDR);
 		src = &header_lsap->header.destination_address[0];
-	} else if(IS_8023_2_SNAP(flags)) {
+	} else if (IS_8023_2_SNAP(flags)) {
 		header = PACKET_PREFIX(packet, eth_header_snap_t);
 		if (!header)
@@ -746,5 +725,5 @@
 		header->lsap.ctrl = IEEE_8023_2_UI;
 		
-		for (i = 0; i < 3; ++ i)
+		for (i = 0; i < 3; i++)
 			header->snap.protocol[i] = 0;
 		
@@ -760,5 +739,5 @@
 			return ENOMEM;
 		
-		for (i = 0; i < 7; ++ i)
+		for (i = 0; i < 7; i++)
 			preamble->preamble[i] = ETH_PREAMBLE;
 		
@@ -787,5 +766,5 @@
  * @return		EINVAL if the service parameter is not known.
  */
-static int eth_send_message(device_id_t device_id, packet_t *packet,
+static int eth_send_message(nic_device_id_t device_id, packet_t *packet,
     services_t sender)
 {
@@ -813,5 +792,5 @@
 	do {
 		rc = eth_prepare_packet(device->flags, next,
-		    (uint8_t *) device->addr->value, ethertype, device->mtu);
+		    (uint8_t *) &device->addr.address, ethertype, device->mtu);
 		if (rc != EOK) {
 			/* Release invalid packet */
@@ -825,20 +804,61 @@
 			next = pq_next(next);
 		}
-	} while(next);
+	} while (next);
 	
 	/* Send packet queue */
-	if (packet) {
-		netif_send_msg(device->sess, device_id, packet,
-		    SERVICE_ETHERNET);
-	}
-
+	if (packet)
+		nic_send_message(device->sess, packet_get_id(packet));
+	
 	fibril_rwlock_read_unlock(&eth_globals.devices_lock);
 	return EOK;
 }
 
+static int eth_addr_changed(nic_device_id_t device_id)
+{
+	nic_address_t address;
+	size_t length;
+	ipc_callid_t data_callid;
+	if (!async_data_write_receive(&data_callid, &length)) {
+		async_answer_0(data_callid, EINVAL);
+		return EINVAL;
+	}
+	if (length > sizeof (nic_address_t)) {
+		async_answer_0(data_callid, ELIMIT);
+		return ELIMIT;
+	}
+	if (async_data_write_finalize(data_callid, &address, length) != EOK) {
+		return EINVAL;
+	}
+
+	fibril_rwlock_write_lock(&eth_globals.devices_lock);
+	/* An existing device? */
+	eth_device_t *device = eth_devices_find(&eth_globals.devices, device_id);
+	if (device) {
+		printf("Device %d changing address from " PRIMAC " to " PRIMAC "\n",
+			device_id, ARGSMAC(device->addr.address), ARGSMAC(address.address));
+		memcpy(&device->addr, &address, sizeof (nic_address_t));
+		fibril_rwlock_write_unlock(&eth_globals.devices_lock);
+
+		/* Notify all upper layer modules */
+		fibril_rwlock_read_lock(&eth_globals.protos_lock);
+		int index;
+		for (index = 0; index < eth_protos_count(&eth_globals.protos); index++) {
+			eth_proto_t *proto = eth_protos_get_index(&eth_globals.protos, index);
+			if (proto->sess != NULL) {
+				il_addr_changed_msg(proto->sess, device->device_id,
+						ETH_ADDR, address.address);
+			}
+		}
+
+		fibril_rwlock_read_unlock(&eth_globals.protos_lock);
+		return EOK;
+	} else {
+		return ENOENT;
+	}
+}
+
 int nil_module_message(ipc_callid_t callid, ipc_call_t *call,
     ipc_call_t *answer, size_t *answer_count)
 {
-	measured_string_t *address;
 	packet_t *packet;
 	size_t addrlen;
@@ -861,5 +881,5 @@
 	case NET_NIL_DEVICE:
 		return eth_device_message(IPC_GET_DEVICE(*call),
-		    IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
+		    IPC_GET_DEVICE_HANDLE(*call), IPC_GET_MTU(*call));
 	case NET_NIL_SEND:
 		rc = packet_translate_remote(eth_globals.net_sess, &packet,
@@ -867,4 +887,5 @@
 		if (rc != EOK)
 			return rc;
+		
 		return eth_send_message(IPC_GET_DEVICE(*call), packet,
 		    IPC_GET_SERVICE(*call));
@@ -874,4 +895,5 @@
 		if (rc != EOK)
 			return rc;
+		
 		IPC_SET_ADDR(*answer, addrlen);
 		IPC_SET_PREFIX(*answer, prefix);
@@ -879,17 +901,40 @@
 		IPC_SET_SUFFIX(*answer, suffix);
 		*answer_count = 4;
+		
 		return EOK;
 	case NET_NIL_ADDR:
-		rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_LOCAL_ADDR,
-		    &address);
+		rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_LOCAL_ADDR);
 		if (rc != EOK)
 			return rc;
-		return measured_strings_reply(address, 1);
+		
+		IPC_SET_ADDR(*answer, ETH_ADDR);
+		*answer_count = 1;
+		
+		return EOK;
 	case NET_NIL_BROADCAST_ADDR:
-		rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_BROADCAST_ADDR,
-		    &address);
+		rc = eth_addr_message(IPC_GET_DEVICE(*call), ETH_BROADCAST_ADDR);
 		if (rc != EOK)
-			return EOK;
-		return measured_strings_reply(address, 1);
+			return rc;
+		
+		IPC_SET_ADDR(*answer, ETH_ADDR);
+		*answer_count = 1;
+		
+		return EOK;
+	case NET_NIL_DEVICE_STATE:
+		nil_device_state_msg_local(IPC_GET_DEVICE(*call), IPC_GET_STATE(*call));
+		async_answer_0(callid, EOK);
+		return EOK;
+	case NET_NIL_RECEIVED:
+		rc = packet_translate_remote(eth_globals.net_sess, &packet,
+		    IPC_GET_ARG2(*call));
+		if (rc == EOK)
+			rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);
+		
+		async_answer_0(callid, (sysarg_t) rc);
+		return rc;
+	case NET_NIL_ADDR_CHANGED:
+		rc = eth_addr_changed(IPC_GET_DEVICE(*call));
+		async_answer_0(callid, (sysarg_t) rc);
+		return rc;
 	}
 	
Index: uspace/srv/net/nil/eth/eth.h
===================================================================
--- uspace/srv/net/nil/eth/eth.h	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/nil/eth/eth.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2009 Lukas Mejdrech
+ * Copyright (c) 2011 Radim Vansa
  * All rights reserved.
  *
@@ -43,4 +44,5 @@
 #include <net/device.h>
 #include <adt/measured_strings.h>
+#include <devman.h>
 
 /** Ethernet address length. */
@@ -220,7 +222,7 @@
 struct eth_device {
 	/** Device identifier. */
-	device_id_t device_id;
-	/** Device driver service. */
-	services_t service;
+	nic_device_id_t device_id;
+	/** Device handle */
+	devman_handle_t handle;
 	/** Driver session. */
 	async_sess_t *sess;
@@ -236,8 +238,5 @@
 	
 	/** Actual device hardware address. */
-	measured_string_t *addr;
-	
-	/** Actual device hardware address data. */
-	uint8_t *addr_data;
+	nic_address_t addr;
 };
 
@@ -270,5 +269,5 @@
 	
 	/** Broadcast device hardware address. */
-	measured_string_t *broadcast_addr;
+	uint8_t broadcast_addr[ETH_ADDR];
 };
 
Index: uspace/srv/net/nil/nildummy/nildummy.c
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/nil/nildummy/nildummy.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2009 Lukas Mejdrech
+ * Copyright (c) 2011 Radim Vansa
  * All rights reserved.
  *
@@ -36,4 +37,5 @@
  */
 
+#include <assert.h>
 #include <async.h>
 #include <malloc.h>
@@ -50,5 +52,7 @@
 #include <net/packet.h>
 #include <packet_remote.h>
-#include <netif_remote.h>
+#include <packet_client.h>
+#include <devman.h>
+#include <device/nic.h>
 #include <nil_skel.h>
 #include "nildummy.h"
@@ -65,5 +69,5 @@
 DEVICE_MAP_IMPLEMENT(nildummy_devices, nildummy_device_t);
 
-int nil_device_state_msg_local(device_id_t device_id, sysarg_t state)
+int nil_device_state_msg_local(nic_device_id_t device_id, sysarg_t state)
 {
 	fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
@@ -91,42 +95,4 @@
 	
 	return rc;
-}
-
-/** Process IPC messages from the registered device driver modules
- *
- * @param[in]     iid   Message identifier.
- * @param[in,out] icall Message parameters.
- * @param[in]     arg    Local argument.
- *
- */
-static void nildummy_receiver(ipc_callid_t iid, ipc_call_t *icall, void *arg)
-{
-	packet_t *packet;
-	int rc;
-	
-	while (true) {
-		switch (IPC_GET_IMETHOD(*icall)) {
-		case NET_NIL_DEVICE_STATE:
-			rc = nil_device_state_msg_local(IPC_GET_DEVICE(*icall),
-			    IPC_GET_STATE(*icall));
-			async_answer_0(iid, (sysarg_t) rc);
-			break;
-		
-		case NET_NIL_RECEIVED:
-			rc = packet_translate_remote(nildummy_globals.net_sess,
-			    &packet, IPC_GET_PACKET(*icall));
-			if (rc == EOK)
-				rc = nil_received_msg_local(IPC_GET_DEVICE(*icall),
-				    packet, 0);
-			
-			async_answer_0(iid, (sysarg_t) rc);
-			break;
-		
-		default:
-			async_answer_0(iid, (sysarg_t) ENOTSUP);
-		}
-		
-		iid = async_get_call(icall);
-	}
 }
 
@@ -148,6 +114,6 @@
  *
  */
-static int nildummy_device_message(device_id_t device_id, services_t service,
-    size_t mtu)
+static int nildummy_device_message(nic_device_id_t device_id,
+    devman_handle_t handle, size_t mtu)
 {
 	fibril_rwlock_write_lock(&nildummy_globals.devices_lock);
@@ -157,8 +123,8 @@
 	    nildummy_devices_find(&nildummy_globals.devices, device_id);
 	if (device) {
-		if (device->service != service) {
-			printf("Device %d already exists\n", device->device_id);
-			fibril_rwlock_write_unlock(
-			    &nildummy_globals.devices_lock);
+		if (device->handle != handle) {
+			printf("Device %d exists, handles do not match\n",
+			    device->device_id);
+			fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
 			return EEXIST;
 		}
@@ -170,6 +136,6 @@
 			device->mtu = NET_DEFAULT_MTU;
 		
-		printf("Device %d already exists:\tMTU\t= %zu\n",
-		    device->device_id, device->mtu);
+		printf("Device %d already exists (mtu: %zu)\n", device->device_id,
+		    device->mtu);
 		fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
 		
@@ -192,13 +158,13 @@
 	
 	device->device_id = device_id;
-	device->service = service;
+	device->handle = handle;
 	if (mtu > 0)
 		device->mtu = mtu;
 	else
 		device->mtu = NET_DEFAULT_MTU;
-
+	
 	/* Bind the device driver */
-	device->sess = netif_bind_service(device->service, device->device_id,
-	    SERVICE_ETHERNET, nildummy_receiver);
+	device->sess = devman_device_connect(EXCHANGE_SERIALIZE, handle,
+	    IPC_FLAG_BLOCKING);
 	if (device->sess == NULL) {
 		fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
@@ -207,7 +173,8 @@
 	}
 	
+	nic_connect_to_nil(device->sess, SERVICE_NILDUMMY, device_id);
+	
 	/* Get hardware address */
-	int rc = netif_get_addr_req(device->sess, device->device_id,
-	    &device->addr, &device->addr_data);
+	int rc = nic_get_address(device->sess, &device->addr);
 	if (rc != EOK) {
 		fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
@@ -215,4 +182,6 @@
 		return rc;
 	}
+	
+	device->addr_len = ETH_ADDR;
 	
 	/* Add to the cache */
@@ -221,12 +190,10 @@
 	if (index < 0) {
 		fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
-		free(device->addr);
-		free(device->addr_data);
 		free(device);
 		return index;
 	}
 	
-	printf("%s: Device registered (id: %d, service: %d, mtu: %zu)\n",
-	    NAME, device->device_id, device->service, device->mtu);
+	printf("%s: Device registered (id: %d, mtu: %zu)\n", NAME,
+	    device->device_id, device->mtu);
 	fibril_rwlock_write_unlock(&nildummy_globals.devices_lock);
 	return EOK;
@@ -243,8 +210,7 @@
  *
  */
-static int nildummy_addr_message(device_id_t device_id,
-    measured_string_t **address)
-{
-	if (!address)
+static int nildummy_addr_message(nic_device_id_t device_id, size_t *addrlen)
+{
+	if (!addrlen)
 		return EBADMEM;
 	
@@ -258,9 +224,28 @@
 	}
 	
-	*address = device->addr;
+	ipc_callid_t callid;
+	size_t max_len;
+	if (!async_data_read_receive(&callid, &max_len)) {
+		fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
+		return EREFUSED;
+	}
+	
+	if (max_len < device->addr_len) {
+		fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
+		async_data_read_finalize(callid, NULL, 0);
+		return ELIMIT;
+	}
+	
+	int rc = async_data_read_finalize(callid,
+	    (uint8_t *) &device->addr.address, device->addr_len);
+	if (rc != EOK) {
+		fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
+		return rc;
+	}
+	
+	*addrlen = device->addr_len;
 	
 	fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
-	
-	return (*address) ? EOK : ENOENT;
+	return EOK;
 }
 
@@ -278,6 +263,6 @@
  *
  */
-static int nildummy_packet_space_message(device_id_t device_id, size_t *addr_len,
-    size_t *prefix, size_t *content, size_t *suffix)
+static int nildummy_packet_space_message(nic_device_id_t device_id,
+    size_t *addr_len, size_t *prefix, size_t *content, size_t *suffix)
 {
 	if ((!addr_len) || (!prefix) || (!content) || (!suffix))
@@ -303,6 +288,5 @@
 }
 
-int nil_received_msg_local(device_id_t device_id, packet_t *packet,
-    services_t target)
+int nil_received_msg_local(nic_device_id_t device_id, packet_t *packet)
 {
 	fibril_rwlock_read_lock(&nildummy_globals.protos_lock);
@@ -340,5 +324,5 @@
 	nildummy_globals.proto.sess = sess;
 	
-	printf("%s: Protocol registered (service: %d)\n",
+	printf("%s: Protocol registered (service: %#x)\n",
 	    NAME, nildummy_globals.proto.service);
 	
@@ -358,5 +342,5 @@
  *
  */
-static int nildummy_send_message(device_id_t device_id, packet_t *packet,
+static int nildummy_send_message(nic_device_id_t device_id, packet_t *packet,
     services_t sender)
 {
@@ -372,6 +356,5 @@
 	/* Send packet queue */
 	if (packet)
-		netif_send_msg(device->sess, device_id, packet,
-		    SERVICE_NILDUMMY);
+		nic_send_message(device->sess, packet_get_id(packet));
 	
 	fibril_rwlock_read_unlock(&nildummy_globals.devices_lock);
@@ -383,5 +366,4 @@
     ipc_call_t *answer, size_t *answer_count)
 {
-	measured_string_t *address;
 	packet_t *packet;
 	size_t addrlen;
@@ -404,5 +386,5 @@
 	case NET_NIL_DEVICE:
 		return nildummy_device_message(IPC_GET_DEVICE(*call),
-		    IPC_GET_SERVICE(*call), IPC_GET_MTU(*call));
+		    IPC_GET_DEVICE_HANDLE(*call), IPC_GET_MTU(*call));
 	
 	case NET_NIL_SEND:
@@ -427,14 +409,26 @@
 	
 	case NET_NIL_ADDR:
-		rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address);
+	case NET_NIL_BROADCAST_ADDR:
+		rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &addrlen);
 		if (rc != EOK)
 			return rc;
-		return measured_strings_reply(address, 1);
-	
-	case NET_NIL_BROADCAST_ADDR:
-		rc = nildummy_addr_message(IPC_GET_DEVICE(*call), &address);
-		if (rc != EOK)
-			return rc;
-		return measured_strings_reply(address, 1);
+		
+		IPC_SET_ADDR(*answer, addrlen);
+		*answer_count = 1;
+		return rc;
+	case NET_NIL_DEVICE_STATE:
+		rc = nil_device_state_msg_local(IPC_GET_DEVICE(*call),
+		    IPC_GET_STATE(*call));
+		async_answer_0(callid, (sysarg_t) rc);
+		return rc;
+	
+	case NET_NIL_RECEIVED:
+		rc = packet_translate_remote(nildummy_globals.net_sess, &packet,
+		    IPC_GET_ARG2(*call));
+		if (rc == EOK)
+			rc = nil_received_msg_local(IPC_GET_ARG1(*call), packet);
+		
+		async_answer_0(callid, (sysarg_t) rc);
+		return rc;
 	}
 	
Index: uspace/srv/net/nil/nildummy/nildummy.h
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy.h	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/nil/nildummy/nildummy.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2009 Lukas Mejdrech
+ * Copyright (c) 2011 Radim Vansa
  * All rights reserved.
  *
@@ -41,6 +42,6 @@
 #include <fibril_synch.h>
 #include <ipc/services.h>
+#include <ipc/devman.h>
 #include <net/device.h>
-#include <adt/measured_strings.h>
 
 /** Type definition of the dummy nil global data.
@@ -76,9 +77,7 @@
 struct nildummy_device {
 	/** Device identifier. */
-	device_id_t device_id;
-	
-	/** Device driver service. */
-	services_t service;
-	
+	nic_device_id_t device_id;
+	/** Device driver handle. */
+	devman_handle_t handle;
 	/** Driver session. */
 	async_sess_t *sess;
@@ -88,8 +87,7 @@
 	
 	/** Actual device hardware address. */
-	measured_string_t *addr;
-	
-	/** Actual device hardware address data. */
-	uint8_t *addr_data;
+	nic_address_t addr;
+	/** Actual device hardware address length. */
+	size_t addr_len;
 };
 
Index: uspace/srv/net/tl/icmp/icmp.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/tl/icmp/icmp.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -753,5 +753,5 @@
 			return rc;
 		
-		rc = icmp_echo(icmp_id, icmp_seq, ICMP_GET_SIZE(*call),	
+		rc = icmp_echo(icmp_id, icmp_seq, ICMP_GET_SIZE(*call),
 		    ICMP_GET_TIMEOUT(*call), ICMP_GET_TTL(*call),
 		    ICMP_GET_TOS(*call), ICMP_GET_DONT_FRAGMENT(*call),
Index: uspace/srv/net/tl/tcp/sock.c
===================================================================
--- uspace/srv/net/tl/tcp/sock.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/tl/tcp/sock.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -215,5 +215,5 @@
 	tcp_sock_t lsocket;
 	tcp_sock_t fsocket;
-	device_id_t dev_id;
+	nic_device_id_t dev_id;
 	tcp_phdr_t *phdr;
 	size_t phdr_len;
Index: uspace/srv/net/tl/tcp/tcp.c
===================================================================
--- uspace/srv/net/tl/tcp/tcp.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/tl/tcp/tcp.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -114,5 +114,5 @@
 
 /** Process packet received from network layer. */
-static int tcp_received_msg(device_id_t device_id, packet_t *packet,
+static int tcp_received_msg(nic_device_id_t device_id, packet_t *packet,
     services_t error)
 {
@@ -262,5 +262,5 @@
 {
 	struct sockaddr_in dest;
-	device_id_t dev_id;
+	nic_device_id_t dev_id;
 	void *phdr;
 	size_t phdr_len;
Index: uspace/srv/net/tl/udp/udp.c
===================================================================
--- uspace/srv/net/tl/udp/udp.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/net/tl/udp/udp.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -124,5 +124,5 @@
  *			ip_client_process_packet() function.
  */
-static int udp_process_packet(device_id_t device_id, packet_t *packet,
+static int udp_process_packet(nic_device_id_t device_id, packet_t *packet,
     services_t error)
 {
@@ -322,5 +322,5 @@
  *			udp_process_packet() function.
  */
-static int udp_received_msg(device_id_t device_id, packet_t *packet,
+static int udp_received_msg(nic_device_id_t device_id, packet_t *packet,
     services_t receiver, services_t error)
 {
@@ -499,5 +499,5 @@
 	void *ip_header;
 	size_t headerlen;
-	device_id_t device_id;
+	nic_device_id_t device_id;
 	packet_dimension_t *packet_dimension;
 	size_t size;
@@ -617,7 +617,6 @@
 		    htons(flip_checksum(compact_checksum(checksum)));
 		free(ip_header);
-	} else {
-		device_id = DEVICE_INVALID_ID;
-	}
+	} else
+		device_id = NIC_DEVICE_INVALID_ID;
 
 	/* Prepare the first packet fragment */
@@ -806,5 +805,5 @@
 			size = MAX_UDP_FRAGMENT_SIZE;
 			if (tl_get_ip_packet_dimension(udp_globals.ip_sess,
-			    &udp_globals.dimensions, DEVICE_INVALID_ID,
+			    &udp_globals.dimensions, NIC_DEVICE_INVALID_ID,
 			    &packet_dimension) == EOK) {
 				if (packet_dimension->content < size)
Index: uspace/srv/vfs/vfs.c
===================================================================
--- uspace/srv/vfs/vfs.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/vfs/vfs.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -127,4 +127,7 @@
 			vfs_wait_handle(callid, &call);
 			break;
+		case VFS_IN_MTAB_GET:
+			vfs_get_mtab(callid, &call);
+			break;
 		default:
 			async_answer_0(callid, ENOTSUP);
Index: uspace/srv/vfs/vfs.h
===================================================================
--- uspace/srv/vfs/vfs.h	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/vfs/vfs.h	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -150,4 +150,7 @@
 extern list_t fs_list;		/**< List of registered file systems. */
 
+extern fibril_mutex_t fs_mntlist_lock;
+extern list_t fs_mntlist;	/**< List of mounted file systems. */
+
 extern vfs_pair_t rootfs;	/**< Root file system. */
 
@@ -163,6 +166,4 @@
 extern list_t plb_entries;	/**< List of active PLB entries. */
 
-#define MAX_MNTOPTS_LEN		256
-
 /** Holding this rwlock prevents changes in file system namespace. */ 
 extern fibril_rwlock_t namespace_rwlock;
@@ -171,5 +172,5 @@
 extern void vfs_exchange_release(async_exch_t *);
 
-extern fs_handle_t fs_name_to_handle(char *, bool);
+extern fs_handle_t fs_name_to_handle(unsigned int instance, char *, bool);
 extern vfs_info_t *fs_handle_to_info(fs_handle_t);
 
@@ -219,4 +220,5 @@
 extern void vfs_rename(ipc_callid_t, ipc_call_t *);
 extern void vfs_wait_handle(ipc_callid_t, ipc_call_t *);
+extern void vfs_get_mtab(ipc_callid_t, ipc_call_t *);
 
 #endif
Index: uspace/srv/vfs/vfs_ops.c
===================================================================
--- uspace/srv/vfs/vfs_ops.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/vfs/vfs_ops.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -52,4 +52,9 @@
 #include <assert.h>
 #include <vfs/canonify.h>
+#include <vfs/vfs_mtab.h>
+
+FIBRIL_MUTEX_INITIALIZE(mtab_list_lock);
+LIST_INITIALIZE(mtab_list);
+static size_t mtab_size = 0;
 
 /* Forward declarations of static functions. */
@@ -68,5 +73,5 @@
 };
 
-static void vfs_mount_internal(ipc_callid_t rid, service_id_t service_id,
+static int vfs_mount_internal(ipc_callid_t rid, service_id_t service_id,
     fs_handle_t fs_handle, char *mp, char *opts)
 {
@@ -91,5 +96,5 @@
 			fibril_rwlock_write_unlock(&namespace_rwlock);
 			async_answer_0(rid, EBUSY);
-			return;
+			return EBUSY;
 		}
 		
@@ -99,5 +104,5 @@
 			fibril_rwlock_write_unlock(&namespace_rwlock);
 			async_answer_0(rid, rc);
-			return;
+			return rc;
 		}
 		
@@ -106,5 +111,5 @@
 			fibril_rwlock_write_unlock(&namespace_rwlock);
 			async_answer_0(rid, ENOMEM);
-			return;
+			return ENOMEM;
 		}
 		
@@ -135,5 +140,5 @@
 				fibril_rwlock_write_unlock(&namespace_rwlock);
 				async_answer_0(rid, rc);
-				return;
+				return rc;
 			}
 			async_wait_for(msg, &rc);
@@ -142,9 +147,10 @@
 				fibril_rwlock_write_unlock(&namespace_rwlock);
 				async_answer_0(rid, rc);
-				return;
+				return rc;
 			}
 
 			rindex = (fs_index_t) IPC_GET_ARG1(answer);
-			rsize = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(answer), IPC_GET_ARG3(answer));
+			rsize = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(answer),
+			    IPC_GET_ARG3(answer));
 			rlnkcnt = (unsigned) IPC_GET_ARG4(answer);
 			
@@ -165,5 +171,5 @@
 			fibril_rwlock_write_unlock(&namespace_rwlock);
 			async_answer_0(rid, rc);
-			return;
+			return rc;
 		} else {
 			/*
@@ -173,5 +179,5 @@
 			fibril_rwlock_write_unlock(&namespace_rwlock);
 			async_answer_0(rid, ENOENT);
-			return;
+			return ENOENT;
 		}
 	}
@@ -206,5 +212,5 @@
 		async_answer_0(rid, rc);
 		fibril_rwlock_write_unlock(&namespace_rwlock);
-		return;
+		return rc;
 	}
 	
@@ -221,5 +227,5 @@
 		fibril_rwlock_write_unlock(&namespace_rwlock);
 		async_answer_0(rid, rc);
-		return;
+		return rc;
 	}
 	
@@ -257,4 +263,5 @@
 	async_answer_0(rid, rc);
 	fibril_rwlock_write_unlock(&namespace_rwlock);
+	return rc;
 }
 
@@ -276,8 +283,8 @@
 	
 	/*
-	 * For now, don't make use of ARG3, but it can be used to
-	 * carry mount options in the future.
-	 */
-	
+	 * Instance number is passed as ARG3.
+	 */
+	unsigned int instance = IPC_GET_ARG3(*request);
+
 	/* We want the client to send us the mount point. */
 	char *mp;
@@ -335,5 +342,5 @@
 	fs_handle_t fs_handle;
 recheck:
-	fs_handle = fs_name_to_handle(fs_name, false);
+	fs_handle = fs_name_to_handle(instance, fs_name, false);
 	if (!fs_handle) {
 		if (flags & IPC_FLAG_BLOCKING) {
@@ -351,13 +358,49 @@
 	}
 	fibril_mutex_unlock(&fs_list_lock);
-	
-	/* Acknowledge that we know fs_name. */
-	async_answer_0(callid, EOK);
-	
+
+	/* Add the filesystem info to the list of mounted filesystems */
+	mtab_ent_t *mtab_ent = malloc(sizeof(mtab_ent_t));
+	if (!mtab_ent) {
+		async_answer_0(callid, ENOMEM);
+		async_answer_0(rid, ENOMEM);
+		free(mp);
+		free(fs_name);
+		free(opts);
+		return;
+	}
+
 	/* Do the mount */
-	vfs_mount_internal(rid, service_id, fs_handle, mp, opts);
+	rc = vfs_mount_internal(rid, service_id, fs_handle, mp, opts);
+	if (rc != EOK) {
+		async_answer_0(callid, ENOTSUP);
+		async_answer_0(rid, ENOTSUP);
+		free(mtab_ent);
+		free(mp);
+		free(opts);
+		free(fs_name);
+		return;
+	}
+
+	/* Add the filesystem info to the list of mounted filesystems */
+
+	str_cpy(mtab_ent->mp, MAX_PATH_LEN, mp);
+	str_cpy(mtab_ent->fs_name, FS_NAME_MAXLEN, fs_name);
+	str_cpy(mtab_ent->opts, MAX_MNTOPTS_LEN, opts);
+	mtab_ent->instance = instance;
+	mtab_ent->service_id = service_id;
+
+	link_initialize(&mtab_ent->link);
+
+	fibril_mutex_lock(&mtab_list_lock);
+	list_append(&mtab_ent->link, &mtab_list);
+	mtab_size++;
+	fibril_mutex_unlock(&mtab_list_lock);
+
 	free(mp);
 	free(fs_name);
 	free(opts);
+
+	/* Acknowledge that we know fs_name. */
+	async_answer_0(callid, EOK);
 }
 
@@ -432,6 +475,4 @@
 		 */
 		
-		free(mp);
-		
 		exch = vfs_exchange_grab(mr_node->fs_handle);
 		rc = async_req_1_0(exch, VFS_OUT_UNMOUNTED,
@@ -441,4 +482,5 @@
 		if (rc != EOK) {
 			fibril_rwlock_write_unlock(&namespace_rwlock);
+			free(mp);
 			vfs_node_put(mr_node);
 			async_answer_0(rid, rc);
@@ -458,7 +500,7 @@
 		
 		rc = vfs_lookup_internal(mp, L_MP, &mp_res, NULL);
-		free(mp);
 		if (rc != EOK) {
 			fibril_rwlock_write_unlock(&namespace_rwlock);
+			free(mp);
 			vfs_node_put(mr_node);
 			async_answer_0(rid, rc);
@@ -469,4 +511,5 @@
 		if (!mp_node) {
 			fibril_rwlock_write_unlock(&namespace_rwlock);
+			free(mp);
 			vfs_node_put(mr_node);
 			async_answer_0(rid, ENOMEM);
@@ -481,4 +524,5 @@
 		if (rc != EOK) {
 			fibril_rwlock_write_unlock(&namespace_rwlock);
+			free(mp);
 			vfs_node_put(mp_node);
 			vfs_node_put(mr_node);
@@ -498,6 +542,27 @@
 	 */
 	vfs_node_forget(mr_node);
-	
 	fibril_rwlock_write_unlock(&namespace_rwlock);
+
+	fibril_mutex_lock(&mtab_list_lock);
+
+	int found = 0;
+
+	list_foreach(mtab_list, cur) {
+		mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t,
+		    link);
+
+		if (str_cmp(mtab_ent->mp, mp) == 0) {
+			list_remove(&mtab_ent->link);
+			mtab_size--;
+			free(mtab_ent);
+			found = 1;
+			break;
+		}
+	}
+	assert(found);
+	fibril_mutex_unlock(&mtab_list_lock);
+
+	free(mp);
+
 	async_answer_0(rid, EOK);
 }
@@ -1288,4 +1353,69 @@
 }
 
+void vfs_get_mtab(ipc_callid_t rid, ipc_call_t *request)
+{
+	ipc_callid_t callid;
+	ipc_call_t data;
+	sysarg_t rc = EOK;
+	size_t len;
+
+	fibril_mutex_lock(&mtab_list_lock);
+
+	/* Send to the caller the number of mounted filesystems */
+	callid = async_get_call(&data);
+	if (IPC_GET_IMETHOD(data) != VFS_IN_PING) {
+		rc = ENOTSUP;
+		async_answer_0(callid, rc);
+		goto exit;
+	}
+	async_answer_1(callid, EOK, mtab_size);
+
+	list_foreach(mtab_list, cur) {
+		mtab_ent_t *mtab_ent = list_get_instance(cur, mtab_ent_t,
+		    link);
+
+		rc = ENOTSUP;
+
+		if (!async_data_read_receive(&callid, &len)) {
+			async_answer_0(callid, rc);
+			goto exit;
+		}
+
+		(void) async_data_read_finalize(callid, mtab_ent->mp,
+		    str_size(mtab_ent->mp));
+
+		if (!async_data_read_receive(&callid, &len)) {
+			async_answer_0(callid, rc);
+			goto exit;
+		}
+
+		(void) async_data_read_finalize(callid, mtab_ent->opts,
+		    str_size(mtab_ent->opts));
+
+		if (!async_data_read_receive(&callid, &len)) {
+			async_answer_0(callid, rc);
+			goto exit;
+		}
+
+		(void) async_data_read_finalize(callid, mtab_ent->fs_name,
+		    str_size(mtab_ent->fs_name));
+
+		callid = async_get_call(&data);
+
+		if (IPC_GET_IMETHOD(data) != VFS_IN_PING) {
+			async_answer_0(callid, rc);
+			goto exit;
+		}
+
+		rc = EOK;
+		async_answer_2(callid, rc, mtab_ent->instance,
+		    mtab_ent->service_id);
+	}
+
+exit:
+	fibril_mutex_unlock(&mtab_list_lock);
+	async_answer_0(rid, rc);
+}
+
 /**
  * @}
Index: uspace/srv/vfs/vfs_register.c
===================================================================
--- uspace/srv/vfs/vfs_register.c	(revision a52de0ea49d86563c5209f5780a0c9d431c14235)
+++ uspace/srv/vfs/vfs_register.c	(revision 77b1c1a02dd99e5b498edea1b825ebd8bbf04b8b)
@@ -154,5 +154,6 @@
 	 * Check for duplicit registrations.
 	 */
-	if (fs_name_to_handle(fs_info->vfs_info.name, false)) {
+	if (fs_name_to_handle(fs_info->vfs_info.instance,
+	    fs_info->vfs_info.name, false)) {
 		/*
 		 * We already register a fs like this.
@@ -297,5 +298,5 @@
  *
  */
-fs_handle_t fs_name_to_handle(char *name, bool lock)
+fs_handle_t fs_name_to_handle(unsigned int instance, char *name, bool lock)
 {
 	int handle = 0;
@@ -306,5 +307,6 @@
 	list_foreach(fs_list, cur) {
 		fs_info_t *fs = list_get_instance(cur, fs_info_t, fs_link);
-		if (str_cmp(fs->vfs_info.name, name) == 0) {
+		if (str_cmp(fs->vfs_info.name, name) == 0 &&
+		    instance == fs->vfs_info.instance) {
 			handle = fs->fs_handle;
 			break;
