Index: uspace/lib/ext4/libext4_filesystem.c
===================================================================
--- uspace/lib/ext4/libext4_filesystem.c	(revision a9a0982571dbfb12ece912ef802a0a9ac5a71c58)
+++ uspace/lib/ext4/libext4_filesystem.c	(revision d5a78e28ed5adb5e8147f0f71502565b49422e9d)
@@ -354,4 +354,38 @@
 }
 
+
+int ext4_filesystem_release_inode_block(ext4_filesystem_t *fs, ext4_inode_t *inode, uint32_t iblock)
+{
+	int rc;
+	uint32_t fblock;
+
+	// TODO handle with extents
+
+	rc = ext4_filesystem_get_inode_data_block_index(fs, inode, iblock, &fblock);
+	if (rc != EOK) {
+		// TODO error
+		return rc;
+	}
+
+	// Sparse file
+	if (fblock == 0) {
+
+		//
+		return EOK;
+	}
+
+
+	// TODO vyhledat policko s ukazatelem a nastavit nulu
+
+
+	// TODO uvolnit blok v bitmape
+
+	// TODO return
+
+
+	return EOK;
+}
+
+
 /**
  * @}
Index: uspace/lib/ext4/libext4_filesystem.h
===================================================================
--- uspace/lib/ext4/libext4_filesystem.h	(revision a9a0982571dbfb12ece912ef802a0a9ac5a71c58)
+++ uspace/lib/ext4/libext4_filesystem.h	(revision d5a78e28ed5adb5e8147f0f71502565b49422e9d)
@@ -62,5 +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_release_inode_block(ext4_filesystem_t *,
+		ext4_inode_t *, uint32_t);
 #endif
 
Index: uspace/lib/ext4/libext4_inode.c
===================================================================
--- uspace/lib/ext4/libext4_inode.c	(revision a9a0982571dbfb12ece912ef802a0a9ac5a71c58)
+++ uspace/lib/ext4/libext4_inode.c	(revision d5a78e28ed5adb5e8147f0f71502565b49422e9d)
@@ -98,4 +98,10 @@
 }
 
+void ext4_inode_set_direct_block(ext4_inode_t *inode, uint8_t idx, uint32_t fblock)
+{
+	assert(idx < EXT4_INODE_DIRECT_BLOCK_COUNT);
+	inode->blocks[idx] = host2uint32_t_le(fblock);
+}
+
 uint32_t ext4_inode_get_indirect_block(ext4_inode_t *inode, uint8_t idx)
 {
Index: uspace/lib/ext4/libext4_inode.h
===================================================================
--- uspace/lib/ext4/libext4_inode.h	(revision a9a0982571dbfb12ece912ef802a0a9ac5a71c58)
+++ uspace/lib/ext4/libext4_inode.h	(revision d5a78e28ed5adb5e8147f0f71502565b49422e9d)
@@ -166,7 +166,8 @@
 extern uint32_t ext4_inode_get_flags(ext4_inode_t *);
 
-uint32_t ext4_inode_get_direct_block(ext4_inode_t *, uint8_t);
-uint32_t ext4_inode_get_indirect_block(ext4_inode_t *, uint8_t);
-uint32_t ext4_inode_get_extent_block(ext4_inode_t *, uint64_t, service_id_t);
+extern uint32_t ext4_inode_get_direct_block(ext4_inode_t *, uint8_t);
+extern void ext4_inode_set_direct_block(ext4_inode_t *, uint8_t, uint32_t);
+extern uint32_t ext4_inode_get_indirect_block(ext4_inode_t *, uint8_t);
+extern uint32_t ext4_inode_get_extent_block(ext4_inode_t *, uint64_t, service_id_t);
 /*
 uint32_t blocks[EXT4_INODE_BLOCKS]; // Pointers to blocks
Index: uspace/srv/fs/ext4fs/ext4fs_ops.c
===================================================================
--- uspace/srv/fs/ext4fs/ext4fs_ops.c	(revision a9a0982571dbfb12ece912ef802a0a9ac5a71c58)
+++ uspace/srv/fs/ext4fs/ext4fs_ops.c	(revision d5a78e28ed5adb5e8147f0f71502565b49422e9d)
@@ -934,10 +934,74 @@
 
 static int
-ext4fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t size)
-{
-	EXT4FS_DBG("not supported");
-
-	// TODO
-	return ENOTSUP;
+ext4fs_truncate(service_id_t service_id, fs_index_t index, aoff64_t new_size)
+{
+	EXT4FS_DBG("");
+	fs_node_t *fn;
+	ext4fs_node_t *enode;
+	ext4_inode_t *inode;
+	ext4_filesystem_t* fs;
+	aoff64_t old_size;
+	aoff64_t size_diff;
+	int rc;
+
+	rc = ext4fs_node_get(&fn, service_id, index);
+	if (rc != EOK) {
+		return rc;
+	}
+
+	enode = EXT4FS_NODE(fn);
+	inode = enode->inode_ref->inode;
+	fs = enode->instance->filesystem;
+
+	old_size = ext4_inode_get_size(fs->superblock, inode);
+
+	printf("old size = \%llu, new size = \%llu\n", old_size, new_size);
+
+	if (old_size == new_size) {
+		rc = EOK;
+	} else {
+		/** AAAAAAAAAAAAAAAAAAAA */
+
+		//int rc;
+		uint32_t block_size;
+		uint32_t blocks_count, total_blocks;
+		uint32_t i;
+
+		block_size  = ext4_superblock_get_block_size(fs->superblock);
+
+		if (old_size < new_size) {
+			// TODO don't return immediately
+			EXT4FS_DBG("expand the file");
+			return EINVAL;
+		}
+
+		EXT4FS_DBG("cut the end of the file !");
+
+		size_diff = old_size - new_size;
+		blocks_count = size_diff / block_size;
+		if (size_diff % block_size != 0) {
+			blocks_count++;
+		}
+
+		total_blocks = old_size / block_size;
+		if (old_size % block_size != 0) {
+			total_blocks++;
+		}
+
+		// TODO dirty add to inode_ref_t
+		//ino_i->dirty = true;
+
+		for (i = 0; i< blocks_count; ++i) {
+			// TODO check retval
+			ext4_filesystem_release_inode_block(fs, inode, total_blocks - i);
+			// TODO subtract inode->size
+		}
+
+		/** BBBBBBBBBBBBBBBBBBBB */
+
+	}
+
+	ext4fs_node_put(fn);
+	return rc;
 }
 
