X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=extras%2Fvolume_id%2Flib%2Ffat.c;h=c0cfed82c008ccfd9d18c3a37f466f45ea7abbcf;hb=cc02d72c82d4ebc2c0803bae0c94707e9d1eea83;hp=e5a5cc119180b025b59225f7379640867508f309;hpb=0565a00a4cfdabd325bf2e117620d5f15dd46cda;p=elogind.git diff --git a/extras/volume_id/lib/fat.c b/extras/volume_id/lib/fat.c index e5a5cc119..c0cfed82c 100644 --- a/extras/volume_id/lib/fat.c +++ b/extras/volume_id/lib/fat.c @@ -281,10 +281,6 @@ int volume_id_probe_vfat(struct volume_id *id, uint64_t off, uint64_t size) if (buf == NULL) return -1; - /* check signature */ - if (buf[510] != 0x55 || buf[511] != 0xaa) - return -1; - vs = (struct vfat_super_block *) buf; if (memcmp(vs->sysid, "NTFS", 4) == 0) return -1; @@ -305,12 +301,17 @@ int volume_id_probe_vfat(struct volume_id *id, uint64_t off, uint64_t size) if (memcmp(vs->type.fat.magic, "FAT12 ", 8) == 0) goto magic; + /* check signature */ + if (buf[510] != 0x55 || buf[511] != 0xaa) + return -1; + /* some old floppies don't have a magic, expect the boot jump address to match */ if ((vs->boot_jump[0] != 0xeb || vs->boot_jump[2] != 0x90) && vs->boot_jump[0] != 0xe9) return -1; magic: + info("magic found\n"); /* reserverd sector count */ if (!vs->reserved) return -1; @@ -333,6 +334,7 @@ magic: if (sector_size == 0 || ((sector_size & (sector_size-1)) != 0)) return -1; + info("checks passed\n"); dbg("sector_size 0x%x\n", sector_size); dbg("sectors_per_cluster 0x%x\n", vs->sectors_per_cluster); @@ -346,9 +348,9 @@ magic: dbg("sect_count 0x%x\n", sect_count); fat_length = le16_to_cpu(vs->fat_length); - dbg("fat_length 0x%x\n", fat_length); + info("fat_length 0x%x\n", fat_length); fat32_length = le32_to_cpu(vs->type.fat32.fat32_length); - dbg("fat32_length 0x%x\n", fat32_length); + info("fat32_length 0x%x\n", fat32_length); if (fat_length) fat_size = fat_length * vs->fats; @@ -356,15 +358,15 @@ magic: fat_size = fat32_length * vs->fats; else return -1; - dbg("fat_size 0x%x\n", fat_size); + info("fat_size 0x%x\n", fat_size); dir_size = ((dir_entries * sizeof(struct vfat_dir_entry)) + (sector_size-1)) / sector_size; - dbg("dir_size 0x%x\n", dir_size); + info("dir_size 0x%x\n", dir_size); cluster_count = sect_count - (reserved + fat_size + dir_size); cluster_count /= vs->sectors_per_cluster; - dbg("cluster_count 0x%x\n", cluster_count); + info("cluster_count 0x%x\n", cluster_count); /* must be FAT32 */ if (!fat_length && fat32_length) @@ -408,16 +410,30 @@ magic: goto found; fat32: - /* FAT32 should have a valid signature in the fsinfo block */ + info("looking for FAT32\n"); + /* + * FAT32 should have a valid signature in the fsinfo block, + * but also allow all bytes set to '\0', because some volumes + * do not set the signature at all. + */ fsinfo_sect = le16_to_cpu(vs->type.fat32.fsinfo_sector); buf = volume_id_get_buffer(id, off + (fsinfo_sect * sector_size), 0x200); if (buf == NULL) return -1; fsinfo = (struct fat32_fsinfo *) buf; - if (memcmp(fsinfo->signature1, "\x52\x52\x61\x41", 4) != 0) + info("signature1: 0x%02x%02x%02x%02x\n", + fsinfo->signature1[0], fsinfo->signature1[1], + fsinfo->signature1[2], fsinfo->signature1[3]); + info("signature2: 0x%02x%02x%02x%02x\n", + fsinfo->signature2[0], fsinfo->signature2[1], + fsinfo->signature2[2], fsinfo->signature2[3]); + if (memcmp(fsinfo->signature1, "\x52\x52\x61\x41", 4) != 0 && + memcmp(fsinfo->signature1, "\x00\x00\x00\x00", 4) != 0) return -1; - if (memcmp(fsinfo->signature2, "\x72\x72\x41\x61", 4) != 0) + if (memcmp(fsinfo->signature2, "\x72\x72\x41\x61", 4) != 0 && + memcmp(fsinfo->signature2, "\x00\x00\x00\x00", 4) != 0) return -1 ; + info("FAT32 signatures ok\n"); vs = (struct vfat_super_block *) volume_id_get_buffer(id, off, 0x200); if (vs == NULL) @@ -487,6 +503,7 @@ fat32: found: volume_id_set_usage(id, VOLUME_ID_FILESYSTEM); id->type = "vfat"; - + /* we think this is fat, but we make sure no other signatures are found */ + id->force_unique_result = 1; return 0; }