summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-11-29 11:00:48 +0100
committerAnton Kling <anton@kling.gg>2024-11-29 11:00:48 +0100
commit1b49c460ec983eb23cace256d459b664d8a0841f (patch)
treeb008f408cdfc0dd79be671f187f01addf031d0cd
parentfd685bad3b3835536c5b0f5b5b18f5ab13f32bf4 (diff)
ext2: Handle "zero" blocks
Any blocks with the value zero appear to indicate a region completly filled to zeros. I don't see this anywhere in the spec but it does make sense and the behavior matches files that I have on my FreeBSD machine so I guess it must be valid.
-rw-r--r--kernel/fs/ext2.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/kernel/fs/ext2.c b/kernel/fs/ext2.c
index dc56ea1..948b0af 100644
--- a/kernel/fs/ext2.c
+++ b/kernel/fs/ext2.c
@@ -623,16 +623,17 @@ int read_inode(int inode_num, u8 *data, u64 size, u64 offset, u64 *file_size) {
int bytes_read = 0;
for (int i = block_start; size; i++) {
+ int read_len = ((size + block_offset) > block_byte_size)
+ ? (block_byte_size - block_offset)
+ : size;
+
u32 block = get_block(inode, i);
if (0 == block) {
- klog(LOG_WARN, "Filesystem EXT2: Unable to find block");
- return -1;
+ memset(data + bytes_read, 0, read_len);
+ } else {
+ ext2_read_block(block, data + bytes_read, read_len, block_offset);
}
- int read_len = ((size + block_offset) > block_byte_size)
- ? (block_byte_size - block_offset)
- : size;
- ext2_read_block(block, data + bytes_read, read_len, block_offset);
block_offset = 0;
bytes_read += read_len;
size -= read_len;