From a1466c94164f10385ec48334897df1e0c151b2a9 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Fri, 10 Nov 2023 14:20:05 +0200 Subject: [PATCH] blkid: Add support for > 64k cluster NTFS volumes. Windows 10 Creators Edition introduced larger cluster sizes for NTFS, but since the number of sectors per cluster is stored as an 8-bit integer and 128 is the largest power of 2 that can be represented as an unsigned 8-bit integer, larger cluster sizes are encoded as a bitshift value / power of two counted down from the value 255. I.e. past the sectors_per_cluster value 128 the actual number of sectors per cluster is calculated as 2^(256 - sectors_per_cluster). --- lib/blkid/probe.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c index 6a3bb2478..a79aa5a07 100644 --- a/lib/blkid/probe.c +++ b/lib/blkid/probe.c @@ -701,6 +701,21 @@ static int probe_ntfs(struct blkid_probe *probe, bytes_per_sector = ns->bios_parameter_block[0] + (ns->bios_parameter_block[1] << 8); sectors_per_cluster = ns->bios_parameter_block[2]; + if (sectors_per_cluster >= 244 && sectors_per_cluster <= 248 && + (bytes_per_sector << (256 - sectors_per_cluster)) <= 2097152) + { + /* Special case: Above the value 128, the number of sectors per + * cluster is encoded as a power of 2 / bitshift value, but only + * up to and including the maximum cluster size, 2 MiB. */ + sectors_per_cluster = 1 << (256 - sectors_per_cluster); + } + else if (sectors_per_cluster > 128 || + (sectors_per_cluster & (sectors_per_cluster - 1))) + { + /* Sectors per cluster out of range or not a power of 2. Not a + * valid NTFS volume. */ + return 1; + } if ((bytes_per_sector < 512) || (sectors_per_cluster == 0)) return 1;