From: Thomas Weißschuh Date: Sun, 20 Nov 2022 04:50:16 +0000 (+0100) Subject: libblkid: dos: ignore exfat superblocks X-Git-Tag: v2.39-rc1~415^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8a0f04e614276ef97f66f52b32f10dd56df09e40;p=thirdparty%2Futil-linux.git libblkid: dos: ignore exfat superblocks --- diff --git a/libblkid/src/partitions/dos.c b/libblkid/src/partitions/dos.c index 6e758ecaaa..5c7718c3e2 100644 --- a/libblkid/src/partitions/dos.c +++ b/libblkid/src/partitions/dos.c @@ -19,6 +19,8 @@ /* see superblocks/vfat.c */ extern int blkid_probe_is_vfat(blkid_probe pr); +/* see superblocks/exfat.c */ +extern int blkid_probe_is_exfat(blkid_probe pr); static const struct dos_subtypes { unsigned char type; @@ -218,7 +220,7 @@ static int probe_dos_pt(blkid_probe pr, * either the boot sector of a FAT filesystem or a DOS-type * partition table. */ - if (blkid_probe_is_vfat(pr) == 1) { + if (blkid_probe_is_vfat(pr) == 1 || blkid_probe_is_exfat(pr) == 1) { DBG(LOWPROBE, ul_debug("probably FAT -- ignore")); goto nothing; } diff --git a/libblkid/src/superblocks/exfat.c b/libblkid/src/superblocks/exfat.c index 4b6414fde9..e760604908 100644 --- a/libblkid/src/superblocks/exfat.c +++ b/libblkid/src/superblocks/exfat.c @@ -158,26 +158,66 @@ static int exfat_validate_checksum(blkid_probe pr, return 1; } -static int probe_exfat(blkid_probe pr, const struct blkid_idmag *mag) +static int exfat_valid_superblock(blkid_probe pr, const struct exfat_super_block *sb) { - struct exfat_super_block *sb; - struct exfat_entry_label *label; - - sb = blkid_probe_get_sb(pr, mag, struct exfat_super_block); - if (!sb || !CLUSTER_SIZE(sb)) - return errno ? -errno : BLKID_PROBE_NONE; - if (le16_to_cpu(sb->BootSignature) != 0xAA55) - return BLKID_PROBE_NONE; + return 0; + + if (!CLUSTER_SIZE(sb)) + return 0; if (memcmp(sb->JumpBoot, "\xEB\x76\x90", 3) != 0) - return BLKID_PROBE_NONE; + return 0; for (size_t i = 0; i < sizeof(sb->MustBeZero); i++) if (sb->MustBeZero[i] != 0x00) - return BLKID_PROBE_NONE; + return 0; if (!exfat_validate_checksum(pr, sb)) + return 0; + + return 1; +} + +/* function prototype to avoid warnings (duplicate in partitions/dos.c) */ +extern int blkid_probe_is_exfat(blkid_probe pr); + +/* + * This function is used by MBR partition table parser to avoid + * misinterpretation of exFAT filesystem. + */ +int blkid_probe_is_exfat(blkid_probe pr) +{ + struct exfat_super_block *sb; + const struct blkid_idmag *mag = NULL; + int rc; + + rc = blkid_probe_get_idmag(pr, &vfat_idinfo, NULL, &mag); + if (rc < 0) + return rc; /* error */ + if (rc != BLKID_PROBE_OK || !mag) + return 0; + + sb = blkid_probe_get_sb(pr, mag, struct exfat_super_block); + if (!sb) + return 0; + + if (memcmp(sb->FileSystemName, "EXFAT ", 8) != 0) + return 0; + + return exfat_valid_superblock(pr, sb); +} + +static int probe_exfat(blkid_probe pr, const struct blkid_idmag *mag) +{ + struct exfat_super_block *sb; + struct exfat_entry_label *label; + + sb = blkid_probe_get_sb(pr, mag, struct exfat_super_block); + if (!sb) + return errno ? -errno : BLKID_PROBE_NONE; + + if (!exfat_valid_superblock(pr, sb)) return BLKID_PROBE_NONE; label = find_label(pr, sb);