u64 logical = 0, phys = 0, size = 0;
        u32 flags = 0;
        int ret = 0;
-       bool compr_cluster = false;
+       bool compr_cluster = false, compr_appended;
        unsigned int cluster_size = F2FS_I(inode)->i_cluster_size;
+       unsigned int count_in_cluster = 0;
        loff_t maxbytes;
 
        if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
        map.m_next_pgofs = &next_pgofs;
        map.m_seg_type = NO_CHECK_TYPE;
 
-       if (compr_cluster)
-               map.m_len = cluster_size - 1;
+       if (compr_cluster) {
+               map.m_lblk += 1;
+               map.m_len = cluster_size - count_in_cluster;
+       }
 
        ret = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_FIEMAP);
        if (ret)
                goto out;
 
        /* HOLE */
-       if (!(map.m_flags & F2FS_MAP_FLAGS)) {
+       if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) {
                start_blk = next_pgofs;
 
                if (blks_to_bytes(inode, start_blk) < blks_to_bytes(inode,
                flags |= FIEMAP_EXTENT_LAST;
        }
 
+       compr_appended = false;
+       /* In a case of compressed cluster, append this to the last extent */
+       if (compr_cluster && ((map.m_flags & F2FS_MAP_UNWRITTEN) ||
+                       !(map.m_flags & F2FS_MAP_FLAGS))) {
+               compr_appended = true;
+               goto skip_fill;
+       }
+
        if (size) {
                flags |= FIEMAP_EXTENT_MERGED;
                if (IS_ENCRYPTED(inode))
        if (start_blk > last_blk)
                goto out;
 
-       if (compr_cluster) {
-               compr_cluster = false;
-
-
-               logical = blks_to_bytes(inode, start_blk - 1);
-               phys = blks_to_bytes(inode, map.m_pblk);
-               size = blks_to_bytes(inode, cluster_size);
-
-               flags |= FIEMAP_EXTENT_ENCODED;
-
-               start_blk += cluster_size - 1;
-
-               if (start_blk > last_blk)
-                       goto out;
-
-               goto prep_next;
-       }
-
+skip_fill:
        if (map.m_pblk == COMPRESS_ADDR) {
                compr_cluster = true;
-               start_blk++;
-               goto prep_next;
-       }
-
-       logical = blks_to_bytes(inode, start_blk);
-       phys = blks_to_bytes(inode, map.m_pblk);
-       size = blks_to_bytes(inode, map.m_len);
-       flags = 0;
-       if (map.m_flags & F2FS_MAP_UNWRITTEN)
-               flags = FIEMAP_EXTENT_UNWRITTEN;
+               count_in_cluster = 1;
+       } else if (compr_appended) {
+               unsigned int appended_blks = cluster_size -
+                                               count_in_cluster + 1;
+               size += blks_to_bytes(inode, appended_blks);
+               start_blk += appended_blks;
+               compr_cluster = false;
+       } else {
+               logical = blks_to_bytes(inode, start_blk);
+               phys = __is_valid_data_blkaddr(map.m_pblk) ?
+                       blks_to_bytes(inode, map.m_pblk) : 0;
+               size = blks_to_bytes(inode, map.m_len);
+               flags = 0;
+
+               if (compr_cluster) {
+                       flags = FIEMAP_EXTENT_ENCODED;
+                       count_in_cluster += map.m_len;
+                       if (count_in_cluster == cluster_size) {
+                               compr_cluster = false;
+                               size += blks_to_bytes(inode, 1);
+                       }
+               } else if (map.m_flags & F2FS_MAP_UNWRITTEN) {
+                       flags = FIEMAP_EXTENT_UNWRITTEN;
+               }
 
-       start_blk += bytes_to_blks(inode, size);
+               start_blk += bytes_to_blks(inode, size);
+       }
 
 prep_next:
        cond_resched();