Index: uspace/srv/fs/tmpfs/tmpfs_ops.c
===================================================================
--- uspace/srv/fs/tmpfs/tmpfs_ops.c	(revision 594303bc2c2613b4ab83c29adb62ad2b1a616d92)
+++ uspace/srv/fs/tmpfs/tmpfs_ops.c	(revision 8c1eb69344dd85df0749d8d11a5a8aa1508220e3)
@@ -59,11 +59,8 @@
 #define NAMES_BUCKETS		4
 
-/*
- * For now, we don't distinguish between different dev_handles/instances. All
- * requests resolve to the only instance, rooted in the following variable.
- */
-static tmpfs_dentry_t *root;
-
-#define TMPFS_DEV		0	/**< Dummy device handle for TMPFS */
+/** All root nodes have index 0. */
+#define TMPFS_SOME_ROOT		0
+/** Global counter for assigning node indices. Shared by all instances. */
+fs_index_t tmpfs_next_index = 1;
 
 /*
@@ -103,5 +100,5 @@
 static void *tmpfs_root_get(dev_handle_t dev_handle)
 {
-	return root; 
+	return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT); 
 }
 
@@ -143,16 +140,20 @@
 hash_table_t dentries;
 
+#define DENTRIES_KEY_INDEX	0
+#define DENTRIES_KEY_DEV	1
+
 /* Implementation of hash table interface for the dentries hash table. */
-static hash_index_t dentries_hash(unsigned long *key)
-{
-	return *key % DENTRIES_BUCKETS;
-}
-
-static int dentries_compare(unsigned long *key, hash_count_t keys,
+static hash_index_t dentries_hash(unsigned long key[])
+{
+	return key[DENTRIES_KEY_INDEX] % DENTRIES_BUCKETS;
+}
+
+static int dentries_compare(unsigned long key[], hash_count_t keys,
     link_t *item)
 {
 	tmpfs_dentry_t *dentry = hash_table_get_instance(item, tmpfs_dentry_t,
 	    dh_link);
-	return dentry->index == *key;
+	return (dentry->index == key[DENTRIES_KEY_INDEX] &&
+	    dentry->dev_handle == key[DENTRIES_KEY_DEV]);
 }
 
@@ -168,6 +169,4 @@
 };
 
-fs_index_t tmpfs_next_index = 1;
-
 typedef struct {
 	char *name;
@@ -216,4 +215,5 @@
 {
 	dentry->index = 0;
+	dentry->dev_handle = 0;
 	dentry->sibling = NULL;
 	dentry->child = NULL;
@@ -227,13 +227,19 @@
 }
 
-static bool tmpfs_init(void)
-{
-	if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 1, &dentries_ops))
+bool tmpfs_init(void)
+{
+	if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 2, &dentries_ops))
 		return false;
-	root = (tmpfs_dentry_t *) tmpfs_create_node(TMPFS_DEV, L_DIRECTORY);
-	if (!root) {
-		hash_table_destroy(&dentries);
+	
+	return true;
+}
+
+static bool tmpfs_instance_init(dev_handle_t dev_handle)
+{
+	tmpfs_dentry_t *root;
+	
+	root = (tmpfs_dentry_t *) tmpfs_create_node(dev_handle, L_DIRECTORY);
+	if (!root) 
 		return false;
-	}
 	root->lnkcnt = 0;	/* FS root is not linked */
 	return true;
@@ -273,6 +279,9 @@
 tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index)
 {
-	unsigned long key = index;
-	link_t *lnk = hash_table_find(&dentries, &key);
+	unsigned long key[] = {
+		[DENTRIES_KEY_INDEX] = index,
+		[DENTRIES_KEY_DEV] = dev_handle
+	};
+	link_t *lnk = hash_table_find(&dentries, key);
 	if (!lnk)
 		return NULL;
@@ -297,5 +306,9 @@
 		return NULL;
 	}
-	node->index = tmpfs_next_index++;
+	if (!tmpfs_root_get(dev_handle))
+		node->index = TMPFS_SOME_ROOT;
+	else
+		node->index = tmpfs_next_index++;
+	node->dev_handle = dev_handle;
 	if (lflag & L_DIRECTORY) 
 		node->type = TMPFS_DIRECTORY;
@@ -304,6 +317,9 @@
 
 	/* Insert the new node into the dentry hash table. */
-	unsigned long key = node->index;
-	hash_table_insert(&dentries, &key, &node->dh_link);
+	unsigned long key[] = {
+		[DENTRIES_KEY_INDEX] = node->index,
+		[DENTRIES_KEY_DEV] = node->dev_handle
+	};
+	hash_table_insert(&dentries, key, &node->dh_link);
 	return (void *) node;
 }
@@ -385,6 +401,9 @@
 	assert(!dentry->sibling);
 
-	unsigned long key = dentry->index;
-	hash_table_remove(&dentries, &key, 1);
+	unsigned long key[] = {
+		[DENTRIES_KEY_INDEX] = dentry->index,
+		[DENTRIES_KEY_DEV] = dentry->dev_handle
+	};
+	hash_table_remove(&dentries, key, 2);
 
 	hash_table_destroy(&dentry->names);
@@ -422,10 +441,11 @@
 	opts[size] = '\0';
 
-	/* Initialize TMPFS. */
-	if (!root && !tmpfs_init()) {
+	/* Initialize TMPFS instance. */
+	if (!tmpfs_instance_init(dev_handle)) {
 		ipc_answer_0(rid, ENOMEM);
 		return;
 	}
 
+	tmpfs_dentry_t *root = tmpfs_root_get(dev_handle);
 	if (str_cmp(opts, "restore") == 0) {
 		if (tmpfs_restore(dev_handle))
@@ -464,6 +484,9 @@
 	 */
 	link_t *hlp;
-	unsigned long key = index;
-	hlp = hash_table_find(&dentries, &key);
+	unsigned long key[] = {
+		[DENTRIES_KEY_INDEX] = index,
+		[DENTRIES_KEY_DEV] = dev_handle,
+	};
+	hlp = hash_table_find(&dentries, key);
 	if (!hlp) {
 		ipc_answer_0(rid, ENOENT);
@@ -537,6 +560,9 @@
 	 */
 	link_t *hlp;
-	unsigned long key = index;
-	hlp = hash_table_find(&dentries, &key);
+	unsigned long key[] = {
+		[DENTRIES_KEY_INDEX] = index,
+		[DENTRIES_KEY_DEV] = dev_handle
+	};
+	hlp = hash_table_find(&dentries, key);
 	if (!hlp) {
 		ipc_answer_0(rid, ENOENT);
@@ -598,6 +624,9 @@
 	 */
 	link_t *hlp;
-	unsigned long key = index;
-	hlp = hash_table_find(&dentries, &key);
+	unsigned long key[] = {
+		[DENTRIES_KEY_INDEX] = index,
+		[DENTRIES_KEY_DEV] = dev_handle
+	};
+	hlp = hash_table_find(&dentries, key);
 	if (!hlp) {
 		ipc_answer_0(rid, ENOENT);
@@ -633,6 +662,9 @@
 
 	link_t *hlp;
-	unsigned long key = index;
-	hlp = hash_table_find(&dentries, &key);
+	unsigned long key[] = {
+		[DENTRIES_KEY_INDEX] = index,
+		[DENTRIES_KEY_DEV] = dev_handle
+	};
+	hlp = hash_table_find(&dentries, key);
 	if (!hlp) {
 		ipc_answer_0(rid, ENOENT);
