klange / toaruos

A completely-from-scratch hobby operating system: bootloader, kernel, drivers, C library, and userspace including a composited graphical UI, dynamic linker, syntax-highlighting text editor, network stack, etc.
https://toaruos.org/
University of Illinois/NCSA Open Source License
6.13k stars 487 forks source link

Update ext2.c #137

Closed lazear closed 7 years ago

lazear commented 7 years ago

Fix bad triple-indirect block math. Juxtaposition of a '+' and '*' limited current code to just 256 more blocks than the doubly indirect blocks... instead of an additional ~1.6 million blocks per inode

klange commented 7 years ago

I think it's actually supposed to be p + p * p + p * p * p but the math for that overflows with the int sizes in use here. If I remember my logic for doing what's done here, it gives us one page from the tertiary level for... testing? I don't really remember.

lazear commented 7 years ago

I think you are correct, in terms of actual block counts. But in terms of logical block counts (blocks with data), I don't think you need to add in the extra p * p. I do similar to you, where I just automatically allocate all of the indirect blocks along the way, and since they don't hold data, I don't count them when assigning block numbers

klange commented 7 years ago

EXT2_DIRECT_BLOCKS + p + p * p + p * p * p is the correct calculation for the upper limit of the logical block count for this set of blocks (there are p * p * p blocks in this set, there are p * p blocks in the set before it, p before that, and EXT2_DIRECT_BLOCKS are accessible directly). I am planning a rewrite of most of the VFS to use 64-bit offsets and sizes and am rewriting quite a bit of the EXT2 driver at the moment, so this will get fixed as part of that.

lazear commented 7 years ago

You're right... I actually have it down that way in my own code as EXT2_DIRECT_BLOCKS + p + p * p + p * p * p. I'm not sure what I was thinking...