diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-08-28 20:05:24 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-08-28 20:05:24 +0200 |
| commit | 662f5870a878ed29821fd82751629a8a0dd9041f (patch) | |
| tree | ad7607aad41a4eba483c5ca380d269cb4fc296b4 /kapi/gdb/__init__.py | |
| parent | d3125dee241cd68ace6069537d36d32fc709b945 (diff) | |
| download | kernel-662f5870a878ed29821fd82751629a8a0dd9041f.tar.xz kernel-662f5870a878ed29821fd82751629a8a0dd9041f.zip | |
kernel/fs: ext2: fix block allocation on 1 KiB fs
When computing the actual block numbers for a filesystem, care must be
taken to account for which block is the actual first data block. For
1 KiB block size filesystems, that block is actually block 1, not 0.
This is because the first 1 KiB on any ext2 volume is reserved for
bootloader data.
Complicating matters, the bitmaps don't take this into account. They
essentially reflect a logical view, describing which data blocks are
already allocated. On a 1 KiB filesystem, this effectively means that
bit 0 of the allocation bitmap references physical block 1.
Luckily, we don't need to make that determination based on the block
size at all. The superblock already carries the number of the first data
block. That means one can simply add that number, which is 1 in the
1 KiB block size case and 0 otherwise, to the found block index.
Interestingly, this was already caught by accident when locating the
authoritative block group descriptor (BGD) table. A factor of two was
multiplied into the calculation in the case of a 1 KiB block size. This
factor arises because the primary BGD table follows the primary
superblock. Since the superblock is located in physical block 0 in all
cases except for a 1 KiB block size, the BGD table generally lands in
block 1. This implies an offset of 1 block size from the volume start.
In the 1 KiB case, the BGD table lands in block number 2, effectively at
an offset of 2 blocks from the start of the volume.
This changeset makes that calculation explicit in the BGD table locator
code as well. This clarifies the previously obscure factor of 2.
Diffstat (limited to 'kapi/gdb/__init__.py')
0 files changed, 0 insertions, 0 deletions
