Index: uspace/lib/ext4/libext4_directory.c
===================================================================
--- uspace/lib/ext4/libext4_directory.c	(revision dfac604f330840ff2ec0e7f6bf92e7dc51e5ed84)
+++ uspace/lib/ext4/libext4_directory.c	(revision bae2a79e350ae4a3b0b75d5e6598946426b53acb)
@@ -42,8 +42,10 @@
 #include "libext4.h"
 
-static int ext4_directory_iterator_set(ext4_directory_iterator_t *,
-    uint32_t);
-
-
+
+/** Get i-node number from directory entry.
+ *
+ * @param de 	directory entry
+ * @return		i-node number
+ */
 uint32_t ext4_directory_entry_ll_get_inode(ext4_directory_entry_ll_t *de)
 {
@@ -51,4 +53,9 @@
 }
 
+/** Set i-node number to directory entry.
+ *
+ * @param de 	directory entry
+ * @param inode	i-node number
+ */
 void ext4_directory_entry_ll_set_inode(ext4_directory_entry_ll_t *de,
 		uint32_t inode)
@@ -57,4 +64,9 @@
 }
 
+/** Get directory entry length.
+ *
+ * @param de 	directory entry
+ * @return		entry length
+ */
 uint16_t ext4_directory_entry_ll_get_entry_length(
 		ext4_directory_entry_ll_t *de)
@@ -63,4 +75,10 @@
 }
 
+/** Set directory entry length.
+ *
+ * @param de 		directory entry
+ * @param length	entry length
+ */
+
 void ext4_directory_entry_ll_set_entry_length(ext4_directory_entry_ll_t *de,
 		uint16_t length)
@@ -69,4 +87,10 @@
 }
 
+/** Get directory entry name length.
+ *
+ * @param sb	superblock
+ * @param de 	directory entry
+ * @return		entry name length
+ */
 uint16_t ext4_directory_entry_ll_get_name_length(
     ext4_superblock_t *sb, ext4_directory_entry_ll_t *de)
@@ -83,4 +107,10 @@
 }
 
+/** Set directory entry name length.
+ *
+ * @param sb		superblock
+ * @param de 		directory entry
+ * @param length	entry name length
+ */
 void ext4_directory_entry_ll_set_name_length(ext4_superblock_t *sb,
 		ext4_directory_entry_ll_t *de, uint16_t length)
@@ -95,4 +125,10 @@
 }
 
+/** Get i-node type of directory entry.
+ *
+ * @param sb	superblock
+ * @param de 	directory entry
+ * @return 		i-node type (file, dir, etc.)
+ */
 uint8_t ext4_directory_entry_ll_get_inode_type(
 		ext4_superblock_t *sb, ext4_directory_entry_ll_t *de)
@@ -108,4 +144,10 @@
 }
 
+/** Set i-node type of directory entry.
+ *
+ * @param sb	superblock
+ * @param de 	directory entry
+ * @param type 	i-node type (file, dir, etc.)
+ */
 void ext4_directory_entry_ll_set_inode_type(
 		ext4_superblock_t *sb, ext4_directory_entry_ll_t *de, uint8_t type)
@@ -121,9 +163,23 @@
 }
 
+static int ext4_directory_iterator_seek(
+		ext4_directory_iterator_t *, aoff64_t);
+static int ext4_directory_iterator_set(
+		ext4_directory_iterator_t *, uint32_t);
+
+
+/** Initialize directory iterator.
+ *
+ * Set position to the first valid entry from the required position.
+ *
+ * @param it			pointer to iterator to be initialized
+ * @param inode_ref		directory i-node
+ * @param pos			position to start reading entries from
+ * @return				error code
+ */
 int ext4_directory_iterator_init(ext4_directory_iterator_t *it,
-    ext4_filesystem_t *fs, ext4_inode_ref_t *inode_ref, aoff64_t pos)
+		ext4_inode_ref_t *inode_ref, aoff64_t pos)
 {
 	it->inode_ref = inode_ref;
-	it->fs = fs;
 	it->current = NULL;
 	it->current_offset = 0;
@@ -133,5 +189,9 @@
 }
 
-
+/** Jump to the next valid entry
+ *
+ * @param it	initialized iterator
+ * @return 		error code
+ */
 int ext4_directory_iterator_next(ext4_directory_iterator_t *it)
 {
@@ -145,10 +205,18 @@
 }
 
-
+/** Seek to next valid directory entry.
+ *
+ * Here can be jumped to the next data block.
+ *
+ * @param it	initialized iterator
+ * @param pos	position of the next entry
+ * @return		error code
+ */
 int ext4_directory_iterator_seek(ext4_directory_iterator_t *it, aoff64_t pos)
 {
 	int rc;
 
-	uint64_t size = ext4_inode_get_size(it->fs->superblock, it->inode_ref->inode);
+	uint64_t size = ext4_inode_get_size(
+			it->inode_ref->fs->superblock, it->inode_ref->inode);
 
 	/* The iterator is not valid until we seek to the desired position */
@@ -169,5 +237,7 @@
 	}
 
-	uint32_t block_size = ext4_superblock_get_block_size(it->fs->superblock);
+	// Compute next block address
+	uint32_t block_size = ext4_superblock_get_block_size(
+			it->inode_ref->fs->superblock);
 	aoff64_t current_block_idx = it->current_offset / block_size;
 	aoff64_t next_block_idx = pos / block_size;
@@ -192,6 +262,6 @@
 		}
 
-		rc = block_get(&it->current_block, it->fs->device, next_block_phys_idx,
-		    BLOCK_FLAGS_NONE);
+		rc = block_get(&it->current_block, it->inode_ref->fs->device,
+				next_block_phys_idx, BLOCK_FLAGS_NONE);
 		if (rc != EOK) {
 			it->current_block = NULL;
@@ -205,4 +275,10 @@
 }
 
+/** Do some checks before returning iterator.
+ *
+ * @param it			iterator to be checked
+ * @param block_size 	size of data block
+ * @return				error code
+ */
 static int ext4_directory_iterator_set(ext4_directory_iterator_t *it,
     uint32_t block_size)
@@ -232,9 +308,10 @@
 
 	/* Ensure the name length is not too large */
-	if (ext4_directory_entry_ll_get_name_length(it->fs->superblock,
+	if (ext4_directory_entry_ll_get_name_length(it->inode_ref->fs->superblock,
 	    entry) > length-8) {
 		return EIO;
 	}
 
+	// Everything OK - "publish" the entry
 	it->current = entry;
 	return EOK;
@@ -242,9 +319,15 @@
 
 
+/** Uninitialize directory iterator.
+ *
+ * Release all allocated structures.
+ *
+ * @param it	iterator to be finished
+ * @return		error code
+ */
 int ext4_directory_iterator_fini(ext4_directory_iterator_t *it)
 {
 	int rc;
 
-	it->fs = NULL;
 	it->inode_ref = NULL;
 	it->current = NULL;
@@ -260,4 +343,13 @@
 }
 
+/**	Write directory entry to concrete data block.
+ *
+ * @param sb		superblock
+ * @param entry		pointer to entry to be written
+ * @param entry_len	lenght of new entry
+ * @param child		child i-node to be written to new entry
+ * @param name		name of the new entry
+ * @param name_len	length of entry name
+ */
 void ext4_directory_write_entry(ext4_superblock_t *sb,
 		ext4_directory_entry_ll_t *entry, uint16_t entry_len,
@@ -265,10 +357,17 @@
 {
 
-	EXT4FS_DBG("writing entry \%s, len \%u, addr = \%u", name, entry_len, (uint32_t)entry);
-
+	// Check maximum entry length
+	uint32_t block_size = ext4_superblock_get_block_size(sb);
+	assert(entry_len <= block_size);
+
+	// Set basic attributes
 	ext4_directory_entry_ll_set_inode(entry, child->index);
 	ext4_directory_entry_ll_set_entry_length(entry, entry_len);
 	ext4_directory_entry_ll_set_name_length(sb, entry, name_len);
 
+	// Write name
+	memcpy(entry->name, name, name_len);
+
+	// Set type of entry
 	if (ext4_inode_is_type(sb, child->inode, EXT4_INODE_MODE_DIRECTORY)) {
 		ext4_directory_entry_ll_set_inode_type(
@@ -278,13 +377,18 @@
 				sb, entry, EXT4_DIRECTORY_FILETYPE_REG_FILE);
 	}
-	memcpy(entry->name, name, name_len);
-}
-
+
+}
+
+/** Add new entry to the directory.
+ *
+ * @param parent	directory i-node
+ * @param name		name of new entry
+ * @param child		i-node to be referenced from new entry
+ * @return			error code
+ */
 int ext4_directory_add_entry(ext4_inode_ref_t * parent,
 		const char *name, ext4_inode_ref_t *child)
 {
 	int rc;
-
-	EXT4FS_DBG("adding entry to directory \%u [ino = \%u, name = \%s]", parent->index, child->index, name);
 
 	ext4_filesystem_t *fs = parent->fs;
@@ -294,6 +398,4 @@
 			ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX)) {
 
-		EXT4FS_DBG("index");
-
 		rc = ext4_directory_dx_add_entry(parent, child, name);
 
@@ -308,5 +410,5 @@
 		}
 
-		// Needed to clear dir index flag
+		// Needed to clear dir index flag if corrupted
 		ext4_inode_clear_flag(parent->inode, EXT4_INODE_FLAG_INDEX);
 		parent->dirty = true;
@@ -324,5 +426,5 @@
 	uint32_t name_len = strlen(name);
 
-	// Find block, where is space for new entry
+	// Find block, where is space for new entry and try to add
 	bool success = false;
 	for (iblock = 0; iblock < total_blocks; ++iblock) {
@@ -339,4 +441,5 @@
 		}
 
+		// If adding is successful, function can finish
 		rc = ext4_directory_try_insert_entry(fs->superblock, block, child, name, name_len);
 		if (rc == EOK) {
@@ -354,5 +457,5 @@
 	}
 
-	// No free block found - needed to allocate next block
+	// No free block found - needed to allocate next data block
 
 	iblock = 0;
@@ -363,6 +466,4 @@
 	}
 
-	EXT4FS_DBG("using iblock \%u fblock \%u", iblock, fblock);
-
 	// Load new block
 	block_t *new_block;
@@ -387,4 +488,11 @@
 }
 
+/** Find directory entry with passed name.
+ *
+ * @param result	result structure to be returned if entry found
+ * @param parent	directory i-node
+ * @param name		name of entry to be found
+ * @return 			error code
+ */
 int ext4_directory_find_entry(ext4_directory_search_result_t *result,
 		ext4_inode_ref_t *parent, const char *name)
@@ -410,6 +518,12 @@
 		}
 
+		// Needed to clear dir index flag if corrupted
+		ext4_inode_clear_flag(parent->inode, EXT4_INODE_FLAG_INDEX);
+		parent->dirty = true;
+
 		EXT4FS_DBG("index is corrupted - doing linear search");
 	}
+
+	// Linear algorithm
 
 	uint32_t iblock, fblock;
@@ -418,6 +532,8 @@
 	uint32_t total_blocks = inode_size / block_size;
 
+	// Walk through all data blocks
 	for (iblock = 0; iblock < total_blocks; ++iblock) {
 
+		// Load block address
 		rc = ext4_filesystem_get_inode_data_block_index(parent, iblock, &fblock);
 		if (rc != EOK) {
@@ -425,4 +541,5 @@
 		}
 
+		// Load data block
 		block_t *block;
 		rc = block_get(&block, parent->fs->device, fblock, BLOCK_FLAGS_NONE);
@@ -431,5 +548,5 @@
 		}
 
-		// find block entry
+		// Try to find entry in block
 		ext4_directory_entry_ll_t *res_entry;
 		rc = ext4_directory_find_in_block(block, sb, name_len, name, &res_entry);
@@ -440,4 +557,6 @@
 		}
 
+		// Entry not found - put block and continue to the next block
+
 		rc = block_put(block);
 		if (rc != EOK) {
@@ -445,4 +564,6 @@
 		}
 	}
+
+	// Entry was not found
 
 	result->block = NULL;
@@ -453,8 +574,15 @@
 
 
+/** Remove directory entry.
+ *
+ * @param parent	directory i-node
+ * @param name		name of the entry to be removed
+ * @return			error code
+ */
 int ext4_directory_remove_entry(ext4_inode_ref_t *parent, const char *name)
 {
 	int rc;
 
+	// Check if removing from directory
 	if (!ext4_inode_is_type(parent->fs->superblock, parent->inode,
 	    EXT4_INODE_MODE_DIRECTORY)) {
@@ -462,4 +590,5 @@
 	}
 
+	// Try to find entry
 	ext4_directory_search_result_t result;
 	rc  = ext4_directory_find_entry(&result, parent, name);
@@ -468,15 +597,22 @@
 	}
 
+	// Invalidate entry
 	ext4_directory_entry_ll_set_inode(result.dentry, 0);
 
+	// Store entry position in block
 	uint32_t pos = (void *)result.dentry - result.block->data;
 
-	uint32_t offset = 0;
+	// If entry is not the first in block, it must be merged
+	// with previous entry
 	if (pos != 0) {
 
+		uint32_t offset = 0;
+
+		// Start from the first entry in block
 		ext4_directory_entry_ll_t *tmp_dentry = result.block->data;
 		uint16_t tmp_dentry_length =
 				ext4_directory_entry_ll_get_entry_length(tmp_dentry);
 
+		// Find direct predecessor of removed entry
 		while ((offset + tmp_dentry_length) < pos) {
 			offset += ext4_directory_entry_ll_get_entry_length(tmp_dentry);
@@ -488,4 +624,5 @@
 		assert(tmp_dentry_length + offset == pos);
 
+		// Add to removed entry length to predecessor's length
 		uint16_t del_entry_length =
 				ext4_directory_entry_ll_get_entry_length(result.dentry);
@@ -500,9 +637,18 @@
 }
 
-
+/** Try to insert entry to concrete data block.
+ *
+ * @param sb			superblock
+ * @param target_block	block to try to insert entry to
+ * @param child			child i-node to be inserted by new entry
+ * @param name			name of the new entry
+ * @param name_len		length of the new entry name
+ * @return				error code
+ */
 int ext4_directory_try_insert_entry(ext4_superblock_t *sb,
 		block_t *target_block, ext4_inode_ref_t *child,
 		const char *name, uint32_t name_len)
 {
+	// Compute required length entry and align it to 4 bytes
    	uint32_t block_size = ext4_superblock_get_block_size(sb);
    	uint16_t required_len = sizeof(ext4_fake_directory_entry_t) + name_len;
@@ -511,7 +657,10 @@
    	}
 
+   	// Initialize pointers, stop means to upper bound
    	ext4_directory_entry_ll_t *dentry = target_block->data;
    	ext4_directory_entry_ll_t *stop = target_block->data + block_size;
 
+   	// Walk through the block and check for invalid entries
+   	// or entries with free space for new entry
    	while (dentry < stop) {
 
@@ -519,4 +668,5 @@
    		uint16_t rec_len = ext4_directory_entry_ll_get_entry_length(dentry);
 
+   		// If invalid and large enough entry, use it
    		if ((inode == 0) && (rec_len >= required_len)) {
    			ext4_directory_write_entry(sb, dentry, rec_len, child, name, name_len);
@@ -525,4 +675,5 @@
    		}
 
+   		// Valid entry, try to split it
    		if (inode != 0) {
    			uint16_t used_name_len =
@@ -536,4 +687,5 @@
    			uint16_t free_space = rec_len - used_space;
 
+   			// There is free space for new entry
    			if (free_space >= required_len) {
 
@@ -550,25 +702,43 @@
    		}
 
+   		// Jump to the next entry
    		dentry = (void *)dentry + rec_len;
    	}
 
+   	// No free space found for new entry
+
    	return ENOSPC;
 }
 
+/** Try to find entry in block by name.
+ *
+ * @param block		block containing entries
+ * @param sb		superblock
+ * @param name_len	length of entry name
+ * @param name		name of entry to be found
+ * @param res_entry	output pointer to found entry, NULL if not found
+ * @return			error code
+ */
 int ext4_directory_find_in_block(block_t *block,
 		ext4_superblock_t *sb, size_t name_len, const char *name,
 		ext4_directory_entry_ll_t **res_entry)
 {
-
+	// Start from the first entry in block
 	ext4_directory_entry_ll_t *dentry = (ext4_directory_entry_ll_t *)block->data;
+	//Set upper bound for cycling
 	uint8_t *addr_limit = block->data + ext4_superblock_get_block_size(sb);
 
+	// Walk through the block and check entries
 	while ((uint8_t *)dentry < addr_limit) {
 
+		// Termination condition
 		if ((uint8_t*) dentry + name_len > addr_limit) {
 			break;
 		}
 
+		// Valid entry - check it
 		if (dentry->inode != 0) {
+
+			// For more effectivity compare firstly only lengths
 			if (name_len == ext4_directory_entry_ll_get_name_length(sb, dentry)) {
 				// Compare names
@@ -580,17 +750,24 @@
 		}
 
-		// Goto next entry
 		uint16_t dentry_len = ext4_directory_entry_ll_get_entry_length(dentry);
 
+		// Corrupted entry
 		if (dentry_len == 0) {
 			return EINVAL;
 		}
 
+		// Jump to next entry
 		dentry = (ext4_directory_entry_ll_t *)((uint8_t *)dentry + dentry_len);
 	}
 
+	// Entry not found
 	return ENOENT;
 }
 
+/** Simple function to release allocated data from result.
+ *
+ * @param result	search result to destroy
+ * @return			error code
+ */
 int ext4_directory_destroy_result(ext4_directory_search_result_t *result)
 {
Index: uspace/lib/ext4/libext4_directory.h
===================================================================
--- uspace/lib/ext4/libext4_directory.h	(revision dfac604f330840ff2ec0e7f6bf92e7dc51e5ed84)
+++ uspace/lib/ext4/libext4_directory.h	(revision bae2a79e350ae4a3b0b75d5e6598946426b53acb)
@@ -53,7 +53,6 @@
 
 extern int ext4_directory_iterator_init(ext4_directory_iterator_t *,
-		ext4_filesystem_t *, ext4_inode_ref_t *, aoff64_t);
+		ext4_inode_ref_t *, aoff64_t);
 extern int ext4_directory_iterator_next(ext4_directory_iterator_t *);
-extern int ext4_directory_iterator_seek(ext4_directory_iterator_t *, aoff64_t);
 extern int ext4_directory_iterator_fini(ext4_directory_iterator_t *);
 
Index: uspace/lib/ext4/libext4_types.h
===================================================================
--- uspace/lib/ext4/libext4_types.h	(revision dfac604f330840ff2ec0e7f6bf92e7dc51e5ed84)
+++ uspace/lib/ext4/libext4_types.h	(revision bae2a79e350ae4a3b0b75d5e6598946426b53acb)
@@ -386,5 +386,4 @@
 
 typedef struct ext4_directory_iterator {
-	ext4_filesystem_t *fs;
 	ext4_inode_ref_t *inode_ref;
 	block_t *current_block;
Index: uspace/srv/fs/ext4fs/ext4fs_ops.c
===================================================================
--- uspace/srv/fs/ext4fs/ext4fs_ops.c	(revision dfac604f330840ff2ec0e7f6bf92e7dc51e5ed84)
+++ uspace/srv/fs/ext4fs/ext4fs_ops.c	(revision bae2a79e350ae4a3b0b75d5e6598946426b53acb)
@@ -746,5 +746,5 @@
 
 	ext4_directory_iterator_t it;
-	rc = ext4_directory_iterator_init(&it, fs, enode->inode_ref, 0);
+	rc = ext4_directory_iterator_init(&it, enode->inode_ref, 0);
 	if (rc != EOK) {
 		return rc;
@@ -1112,5 +1112,5 @@
 
 	ext4_directory_iterator_t it;
-	rc = ext4_directory_iterator_init(&it, inst->filesystem, inode_ref, pos);
+	rc = ext4_directory_iterator_init(&it, inode_ref, pos);
 	if (rc != EOK) {
 		async_answer_0(callid, rc);
