summaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2019-10-29 09:38:52 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2019-10-29 10:08:15 +0100
commitc3912f75ff2909eadb5c919274139f9fa6cdfe36 (patch)
tree1b707290a38d690035d2a8033819cc4f0e5d991e /fs
parented04267cdfa621537315c96af8eab207b6042019 (diff)
downloadbarebox-c3912f75ff2909eadb5c919274139f9fa6cdfe36.tar.gz
barebox-c3912f75ff2909eadb5c919274139f9fa6cdfe36.tar.xz
fs: ext4: Fix handling of sparse files
Adoption of U-Boot commit: | commit f81db56f2fd6dc16efeaec2961121244765a1f11 | Author: Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de> | Date: Sat Nov 5 22:17:14 2016 +0100 | | ext4: Fix handling of sparse files | | A sparse file may have regions not mapped by any extents, at the start | or at the end of the file, or anywhere between, thus not finding a | matching extent region is never an error. | | Found by python filesystem tests. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'fs')
-rw-r--r--fs/ext4/ext4_common.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c
index 55e837b4bd..2703b55e99 100644
--- a/fs/ext4/ext4_common.c
+++ b/fs/ext4/ext4_common.c
@@ -167,10 +167,11 @@ long int read_allocated_block(struct ext2fs_node *node, int fileblock)
log2_blksz = LOG2_EXT2_BLOCK_SIZE(node->data);
if (le32_to_cpu(inode->flags) & EXT4_EXTENTS_FL) {
+ long int startblock, endblock;
char *buf = zalloc(blksz);
struct ext4_extent_header *ext_block;
struct ext4_extent *extent;
- int i = -1;
+ int i;
if (!buf)
return -ENOMEM;
@@ -186,28 +187,27 @@ long int read_allocated_block(struct ext2fs_node *node, int fileblock)
extent = (struct ext4_extent *)(ext_block + 1);
- do {
- i++;
- if (i >= le16_to_cpu(ext_block->eh_entries))
- break;
- } while (fileblock >= le32_to_cpu(extent[i].ee_block));
+ for (i = 0; i < le16_to_cpu(ext_block->eh_entries); i++) {
+ startblock = le32_to_cpu(extent[i].ee_block);
+ endblock = startblock + le16_to_cpu(extent[i].ee_len);
- if (--i >= 0) {
- fileblock -= le32_to_cpu(extent[i].ee_block);
- if (fileblock >= le16_to_cpu(extent[i].ee_len)) {
+ if (startblock > fileblock) {
+ /* Sparse file */
free(buf);
return 0;
}
- start = le16_to_cpu(extent[i].ee_start_hi);
- start = (start << 32) +
+ if (fileblock < endblock) {
+ start = le16_to_cpu(extent[i].ee_start_hi);
+ start = (start << 32) +
le32_to_cpu(extent[i].ee_start_lo);
- free(buf);
- return fileblock + start;
+ free(buf);
+ return (fileblock - startblock) + start;
+ }
}
free(buf);
- return -EIO;
+ return 0;
}
if (fileblock < INDIRECT_BLOCKS) {