mirror of
https://xff.cz/git/u-boot/
synced 2025-09-02 09:12:08 +02:00
ext4: Correct block number handling, empty block vs. error code
read_allocated block may return block number 0, which is just an indicator a chunk of the file is not backed by a block, i.e. it is sparse. During file deletions, just continue with the next logical block, for other operations treat blocknumber <= 0 as an error. For writes, blocknumber 0 should never happen, as U-Boot always allocates blocks for the whole file. Reading already handles this correctly, i.e. the read buffer is 0-fillled. Not treating block 0 as sparse block leads to FS corruption, e.g. ./sandbox/u-boot -c 'host bind 0 ./sandbox/test/fs/3GB.ext4.img ; ext4write host 0 0 /2.5GB.file 1 ' The 2.5GB.file from the fs test is actually a sparse file. Signed-off-by: Stefan Brüns <stefan.bruens@rwth-aachen.de>
This commit is contained in:
@@ -534,7 +534,7 @@ static int search_dir(struct ext2_inode *parent_inode, char *dirname)
|
||||
/* get the block no allocated to a file */
|
||||
for (blk_idx = 0; blk_idx < directory_blocks; blk_idx++) {
|
||||
blknr = read_allocated_block(parent_inode, blk_idx);
|
||||
if (blknr == 0)
|
||||
if (blknr <= 0)
|
||||
goto fail;
|
||||
|
||||
/* read the directory block */
|
||||
@@ -828,7 +828,7 @@ int ext4fs_filename_unlink(char *filename)
|
||||
/* read the block no allocated to a file */
|
||||
for (blk_idx = 0; blk_idx < directory_blocks; blk_idx++) {
|
||||
blknr = read_allocated_block(g_parent_inode, blk_idx);
|
||||
if (blknr == 0)
|
||||
if (blknr <= 0)
|
||||
break;
|
||||
inodeno = unlink_filename(filename, blknr);
|
||||
if (inodeno != -1)
|
||||
@@ -1590,7 +1590,7 @@ long int read_allocated_block(struct ext2_inode *inode, int fileblock)
|
||||
if (status == 0) {
|
||||
printf("** SI ext2fs read block (indir 1)"
|
||||
"failed. **\n");
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
ext4fs_indir1_blkno =
|
||||
le32_to_cpu(inode->b.blocks.
|
||||
|
Reference in New Issue
Block a user