Index: uspace/srv/fs/ext2fs/ext2fs_ops.c
===================================================================
--- uspace/srv/fs/ext2fs/ext2fs_ops.c	(revision b83e16ffd8bbb76d5ceea375a9c328e56a48f1a8)
+++ uspace/srv/fs/ext2fs/ext2fs_ops.c	(revision df386574003210ff36963b08b86f46840fe22ad9)
@@ -603,8 +603,12 @@
 		ext2fs_read_directory(rid, callid, pos, size, inst, inode_ref);
 	}
-	
-	// Other inode types not supported
-	async_answer_0(callid, ENOTSUP);
-	async_answer_0(rid, ENOTSUP);
+	else {
+		// Other inode types not supported
+		async_answer_0(callid, ENOTSUP);
+		async_answer_0(rid, ENOTSUP);
+	}
+	
+	ext2_filesystem_put_inode_ref(inode_ref);
+	
 }
 
@@ -617,4 +621,5 @@
 	size_t name_size;
 	int rc;
+	bool found = false;
 	
 	rc = ext2_directory_iterator_init(&it, inst->filesystem, inode_ref);
@@ -625,29 +630,50 @@
 	}
 	
+	// Find the index we want to read
+	// Note that we need to iterate and count as
+	// the underlying structure is a linked list
+	// Moreover, we want to skip . and .. entries
+	// as these are not used in HelenOS
 	cur = 0;
 	while (it.current != NULL) {
-		if (it.current->inode != 0) {
-			if (cur == pos) {
-				// This is the dir entry we want to read
-				name_size = ext2_directory_entry_ll_get_name_length(
-					inst->filesystem->superblock, it.current);
-				// The on-disk entry does not contain \0 at the end
-				// end of entry name, so we copy it to new buffer
-				// and the \0 at the end
-				buf = malloc(name_size+1);
-				if (buf == NULL) {
-					ext2_directory_iterator_fini(&it);
-					async_answer_0(callid, ENOMEM);
-					async_answer_0(rid, ENOMEM);
-					return;
-				}
-				memcpy(buf, &it.current->name, name_size);
-				*(buf+name_size) = 0;
-				(void) async_data_read_finalize(callid, buf, name_size+1);
-				break;
+		if (it.current->inode == 0) {
+			goto skip;
+		}
+		
+		name_size = ext2_directory_entry_ll_get_name_length(
+			inst->filesystem->superblock, it.current);
+		
+		// skip . and ..
+		if ((name_size == 1 || name_size == 2) && it.current->name == '.') {
+			if (name_size == 1) {
+				goto skip;
 			}
-			cur++;
+			else if (name_size == 2 && *(&it.current->name+1) == '.') {
+				goto skip;
+			}
 		}
 		
+		// Is this the dir entry we want to read?
+		if (cur == pos) {
+			// The on-disk entry does not contain \0 at the end
+			// end of entry name, so we copy it to new buffer
+			// and add the \0 at the end
+			buf = malloc(name_size+1);
+			if (buf == NULL) {
+				ext2_directory_iterator_fini(&it);
+				async_answer_0(callid, ENOMEM);
+				async_answer_0(rid, ENOMEM);
+				return;
+			}
+			memcpy(buf, &it.current->name, name_size);
+			*(buf+name_size) = 0;
+			found = true;
+			(void) async_data_read_finalize(callid, buf, name_size+1);
+			free(buf);
+			break;
+		}
+		cur++;
+		
+skip:
 		rc = ext2_directory_iterator_next(&it);
 		if (rc != EOK) {
@@ -661,9 +687,15 @@
 	rc = ext2_directory_iterator_fini(&it);
 	if (rc != EOK) {
-		async_answer_0(rid, ENOMEM);
-		return;
-	}
-	
-	async_answer_1(rid, EOK, 1);
+		async_answer_0(rid, rc);
+		return;
+	}
+	
+	if (found) {
+		async_answer_1(rid, EOK, 1);
+	}
+	else {
+		async_answer_0(callid, ENOENT);
+		async_answer_0(rid, ENOENT);
+	}
 }
 
