Skip to content
  • Chao Yu's avatar
    f2fs: fix incorrect mapping for bmap · e2b4e2bc
    Chao Yu authored
    
    
    The test step is like below:
    1. touch file
    2. truncate -s $((1024*1024)) file
    3. fallocate -o 0 -l $((1024*1024)) file
    4. fibmap.f2fs file
    
    Our result of fibmap.f2fs showed below is not correct:
    
    file_pos   start_blk     end_blk        blks
           0    -937166132    -937166132           1
        4096    -937166132    -937166132           1
        8192    -937166132    -937166132           1
       12288    -937166132    -937166132           1
       16384    -937166132    -937166132           1
       20480    -937166132    -937166132           1
    ...
     1040384    -937166132    -937166132           1
     1044480    -937166132    -937166132           1
    
    This is because f2fs_map_blocks will return with no error when meeting
    a hole or preallocated block, the caller __get_data_block will map the
    uninitialized variable value to bh->b_blocknr.
    
    Unfortunately generic_block_bmap will neither check the return value of
    get_data() nor check mapping info of buffer_head, result in returning
    the random block address.
    
    After fixing the issue, our result shows correctly:
    
    file_pos   start_blk     end_blk        blks
           0           0           0         256
    
    Signed-off-by: default avatarChao Yu <chao2.yu@samsung.com>
    Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
    e2b4e2bc