Commit 1c48fda3e5a88159130b4d4805fbdf367212afab

Authored by Gero Schumacher
Committed by Tom Rini
1 parent ef79284e7a

fs: ext4: Problem with ext4load and sparse files

Hi,

when I try to load a sparse file via ext4load, I am getting the error message
'invalid extent'

After a deeper look in the code, it seems to be an issue in the function ext4fs_get_extent_block in fs/ext4/ext4_common.c:

The file starts with 1k of zeros. The blocksize is 1024. So the first extend block contains the following information:

eh_entries: 1
eh_depth: 1
ei_block 1

When the upper layer (ext4fs_read_file) asks for fileblock 0, we are running in the 'invalid extent' error message.
For me it seems, that the code is not prepared for handling a sparse block at the beginning of the file. The following change, solved my problem:

I am really not an expert in ext4 filesystems. Can somebody please have a look at this issue and give me a feedback, if I am totally wrong or not?

Showing 1 changed file with 6 additions and 2 deletions Side-by-side Diff

fs/ext4/ext4_common.c
... ... @@ -1547,8 +1547,12 @@
1547 1547 break;
1548 1548 } while (fileblock >= le32_to_cpu(index[i].ei_block));
1549 1549  
1550   - if (--i < 0)
1551   - return NULL;
  1550 + /*
  1551 + * If first logical block number is higher than requested fileblock,
  1552 + * it is a sparse file. This is handled on upper layer.
  1553 + */
  1554 + if (i > 0)
  1555 + i--;
1552 1556  
1553 1557 block = le16_to_cpu(index[i].ei_leaf_hi);
1554 1558 block = (block << 32) + le32_to_cpu(index[i].ei_leaf_lo);