kernel/devfs: improve devfs_compute_geometry_size

the old code could lead to an odd head count, thus a smaller partition size.
with power of two, this works at least accurately if the size is aligned.
we should probably introduce a new ioctl or extend the current one to avoid this problem.

Change-Id: Ia6c034262b1756e901d6ad76ab17b278b2314631
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5398
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
This commit is contained in:
Jérôme Duval 2022-06-25 09:07:27 +02:00
parent faefd309d9
commit 442298d494

View File

@ -2254,13 +2254,14 @@ void
devfs_compute_geometry_size(device_geometry* geometry, uint64 blockCount,
uint32 blockSize)
{
if (blockCount > UINT32_MAX)
geometry->head_count = (blockCount + UINT32_MAX - 1) / UINT32_MAX;
else
geometry->head_count = 1;
geometry->head_count = 1;
while (blockCount > UINT32_MAX) {
geometry->head_count <<= 1;
blockCount >>= 1;
}
geometry->cylinder_count = 1;
geometry->sectors_per_track = blockCount / geometry->head_count;
geometry->sectors_per_track = blockCount;
geometry->bytes_per_sector = blockSize;
}