Index: uspace/lib/ext4/libext4_bitmap.c
===================================================================
--- uspace/lib/ext4/libext4_bitmap.c	(revision 0f09d4eafbdee6c43063e6f7373e0d09db51359d)
+++ uspace/lib/ext4/libext4_bitmap.c	(revision 35f48f2356b9a59df7e8e43a80a9bc8b567441b8)
@@ -167,10 +167,19 @@
 	rc = ext4_bitmap_find_free_bit_and_set(block->data, &rel_block_idx, block_size);
 
-	// if ENOSPC - try next block group - try next block groups
 
+	if (rc != EOK) {
+		EXT4FS_DBG("no block found");
+		// TODO if ENOSPC - try next block group - try next block groups
+	}
 
+	// TODO decrement superblock free blocks count
+	//uint32_t sb_free_blocks = ext4_superblock_get_free_blocks_count(sb);
+	//sb_free_blocks--;
+	//ext4_superblock_set_free_blocks_count(sb, sb_free_blocks);
 
-
-	// TODO decrement superblock & block group free blocks count
+	uint32_t bg_free_blocks = ext4_block_group_get_free_blocks_count(bg_ref->block_group);
+	bg_free_blocks++;
+	ext4_block_group_set_free_blocks_count(bg_ref->block_group, bg_free_blocks);
+	bg_ref->dirty = true;
 
 	// return
Index: uspace/lib/ext4/libext4_filesystem.c
===================================================================
--- uspace/lib/ext4/libext4_filesystem.c	(revision 0f09d4eafbdee6c43063e6f7373e0d09db51359d)
+++ uspace/lib/ext4/libext4_filesystem.c	(revision 35f48f2356b9a59df7e8e43a80a9bc8b567441b8)
@@ -363,4 +363,93 @@
 
 
+int ext4_filesystem_set_inode_data_block_index(ext4_filesystem_t *fs,
+		ext4_inode_t *inode, aoff64_t iblock, uint32_t fblock)
+{
+
+//	int rc;
+//	uint32_t offset_in_block;
+//	uint32_t current_block;
+//	aoff64_t block_offset_in_level;
+//	int i;
+//	int level;
+//	block_t *block;
+
+	/* Handle inode using extents */
+	if (ext4_superblock_has_feature_compatible(fs->superblock, EXT4_FEATURE_INCOMPAT_EXTENTS) &&
+			ext4_inode_has_flag(inode, EXT4_INODE_FLAG_EXTENTS)) {
+		// TODO
+		return ENOTSUP;
+
+	}
+
+	/* Handle simple case when we are dealing with direct reference */
+	if (iblock < EXT4_INODE_DIRECT_BLOCK_COUNT) {
+		ext4_inode_set_direct_block(inode, (uint32_t)iblock, fblock);
+		return EOK;
+	}
+
+//	/* Determine the indirection level needed to get the desired block */
+//	level = -1;
+//	for (i = 1; i < 4; i++) {
+//		if (iblock < fs->inode_block_limits[i]) {
+//			level = i;
+//			break;
+//		}
+//	}
+//
+//	if (level == -1) {
+//		return EIO;
+//	}
+//
+//	/* Compute offsets for the topmost level */
+//	block_offset_in_level = iblock - fs->inode_block_limits[level-1];
+//	current_block = ext4_inode_get_indirect_block(inode, level-1);
+//	offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
+//
+//	/* Navigate through other levels, until we find the block number
+//	 * or find null reference meaning we are dealing with sparse file
+//	 */
+//	while (level > 0) {
+//		rc = block_get(&block, fs->device, current_block, 0);
+//		if (rc != EOK) {
+//			return rc;
+//		}
+//
+//		current_block = uint32_t_le2host(((uint32_t*)block->data)[offset_in_block]);
+//
+//		rc = block_put(block);
+//		if (rc != EOK) {
+//			return rc;
+//		}
+//
+//		if (current_block == 0) {
+//			/* This is a sparse file */
+//			*fblock = 0;
+//			return EOK;
+//		}
+//
+//		level -= 1;
+//
+//		/* If we are on the last level, break here as
+//		 * there is no next level to visit
+//		 */
+//		if (level == 0) {
+//			break;
+//		}
+//
+//		/* Visit the next level */
+//		block_offset_in_level %= fs->inode_blocks_per_level[level];
+//		offset_in_block = block_offset_in_level / fs->inode_blocks_per_level[level-1];
+//	}
+//
+//	*fblock = current_block;
+//
+//	return EOK;
+//
+//
+
+	return EOK;
+}
+
 int ext4_filesystem_release_inode_block(ext4_filesystem_t *fs,
 		ext4_inode_ref_t *inode_ref, uint32_t iblock)
Index: uspace/lib/ext4/libext4_filesystem.h
===================================================================
--- uspace/lib/ext4/libext4_filesystem.h	(revision 0f09d4eafbdee6c43063e6f7373e0d09db51359d)
+++ uspace/lib/ext4/libext4_filesystem.h	(revision 35f48f2356b9a59df7e8e43a80a9bc8b567441b8)
@@ -62,4 +62,6 @@
 extern int ext4_filesystem_get_inode_data_block_index(ext4_filesystem_t *,
 	ext4_inode_t *, aoff64_t iblock, uint32_t *);
+extern int ext4_filesystem_set_inode_data_block_index(ext4_filesystem_t *,
+		ext4_inode_t *, aoff64_t, uint32_t);
 extern int ext4_filesystem_release_inode_block(ext4_filesystem_t *,
 		ext4_inode_ref_t *, uint32_t);
Index: uspace/srv/fs/ext4fs/ext4fs_ops.c
===================================================================
--- uspace/srv/fs/ext4fs/ext4fs_ops.c	(revision 0f09d4eafbdee6c43063e6f7373e0d09db51359d)
+++ uspace/srv/fs/ext4fs/ext4fs_ops.c	(revision 35f48f2356b9a59df7e8e43a80a9bc8b567441b8)
@@ -929,4 +929,5 @@
 
 	int rc;
+	int flags = BLOCK_FLAGS_NONE;
 	fs_node_t *fn;
 	ext4fs_node_t *enode;
@@ -937,4 +938,5 @@
 	block_t *write_block;
 	uint32_t fblock, iblock;
+	uint32_t old_inode_size;
 
 	rc = ext4fs_node_get(&fn, service_id, index);
@@ -960,4 +962,8 @@
 	bytes = min(len, block_size - (pos % block_size));
 
+	if (bytes == block_size) {
+		flags = BLOCK_FLAGS_NOREAD;
+	}
+
 	EXT4FS_DBG("bytes == \%u", bytes);
 
@@ -966,14 +972,22 @@
 	rc = ext4_filesystem_get_inode_data_block_index(fs, inode_ref->inode, iblock, &fblock);
 
-
-	// TODO allocation if fblock == 0
 	if (fblock == 0) {
 		EXT4FS_DBG("Allocate block !!!");
-
-		return ENOTSUP;
-	}
-
-	// TODO flags
-	rc = block_get(&write_block, service_id, fblock, 0);
+		rc =  ext4_bitmap_alloc_block(fs, inode_ref, &fblock);
+		if (rc != EOK) {
+			ext4fs_node_put(fn);
+			async_answer_0(callid, rc);
+			return rc;
+		}
+
+		ext4_filesystem_set_inode_data_block_index(fs, inode_ref->inode, iblock, fblock);
+		inode_ref->dirty = true;
+
+		flags = BLOCK_FLAGS_NOREAD;
+
+		EXT4FS_DBG("block \%u allocated", fblock);
+	}
+
+	rc = block_get(&write_block, service_id, fblock, flags);
 	if (rc != EOK) {
 		ext4fs_node_put(fn);
@@ -982,10 +996,22 @@
 	}
 
-	/*
-	if (flags == BLOCK_FLAGS_NOREAD)
-		memset(b->data, 0, sbi->block_size);
-	*/
-
-	async_data_write_finalize(callid, write_block->data + (pos % block_size), bytes);
+	EXT4FS_DBG("block loaded");
+
+	if (flags == BLOCK_FLAGS_NOREAD) {
+		EXT4FS_DBG("fill block with zeros");
+		memset(write_block->data, 0, block_size);
+	}
+
+	rc = async_data_write_finalize(callid, write_block->data + (pos % block_size), bytes);
+	if (rc != EOK) {
+		EXT4FS_DBG("error in write finalize \%d", rc);
+	}
+
+	char *data = write_block->data + (pos % block_size);
+	for (uint32_t x = 0; x < bytes; ++x) {
+		printf("%c", data[x]);
+	}
+	printf("\n");
+
 	write_block->dirty = true;
 
@@ -996,12 +1022,15 @@
 	}
 
-	/*
-	if (pos + bytes > ino_i->i_size) {
-		ino_i->i_size = pos + bytes;
-		ino_i->dirty = true;
-	}
-	*nsize = ino_i->i_size;
+	EXT4FS_DBG("writing finished");
+
+	old_inode_size = ext4_inode_get_size(fs->superblock, inode_ref->inode);
+	if (pos + bytes > old_inode_size) {
+		ext4_inode_set_size(inode_ref->inode, pos + bytes);
+		inode_ref->dirty = true;
+	}
+
+	*nsize = ext4_inode_get_size(fs->superblock, inode_ref->inode);
 	*wbytes = bytes;
-	*/
+
 	return ext4fs_node_put(fn);
 }
@@ -1105,8 +1134,19 @@
 static int ext4fs_sync(service_id_t service_id, fs_index_t index)
 {
-	EXT4FS_DBG("not supported");
-
-	// TODO
-	return ENOTSUP;
+	EXT4FS_DBG("");
+
+	int rc;
+	fs_node_t *fn;
+	ext4fs_node_t *enode;
+
+	rc = ext4fs_node_get(&fn, service_id, index);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	enode = EXT4FS_NODE(fn);
+	enode->inode_ref->dirty = true;
+
+	return ext4fs_node_put(fn);
 }
 
