Whamcloud - gitweb
libblkid: Fix false detection of DFSee created filesystems.
authorTheodore Ts'o <tytso@mit.edu>
Sun, 24 Aug 2008 02:11:01 +0000 (22:11 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 24 Aug 2008 21:24:18 +0000 (17:24 -0400)
OS/2 and DFSee creates a pseudo FAT-12/16 header in the first 512
bytes of a filesystem which looks enough like a FAT-12/16 to fool
blkid.  Part of this is because we don't require ms_magic or vs_magic
to be the strings "FAT12 ", "FAT16 ", or "FAT32 ", since some FAT
filesystem formatters don't set ms_magic or vs_magic.  To address
this, we explicitly test for "JFS     " and "HPFS    " in ms_magic,
and if they are found, we assume the filesystem is definitely not
a FAT filesystem.

Addresses-Launchpad-Bug: #255255

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/blkid/probe.c

index e2d8a25..225116a 100644 (file)
@@ -566,25 +566,38 @@ static int probe_fat_nomagic(struct blkid_probe *probe,
                             struct blkid_magic *id __BLKID_ATTR((unused)), 
                             unsigned char *buf)
 {
-       struct vfat_super_block *vs;
+       struct msdos_super_block *ms;
 
-       vs = (struct vfat_super_block *)buf;
+       ms = (struct msdos_super_block *)buf;
 
        /* heads check */
-       if (vs->vs_heads == 0)
+       if (ms->ms_heads == 0)
                return 1;
 
        /* cluster size check*/ 
-       if (vs->vs_cluster_size == 0 ||
-           (vs->vs_cluster_size & (vs->vs_cluster_size-1)))
+       if (ms->ms_cluster_size == 0 ||
+           (ms->ms_cluster_size & (ms->ms_cluster_size-1)))
                return 1;
 
        /* media check */
-       if (vs->vs_media < 0xf8 && vs->vs_media != 0xf0)
+       if (ms->ms_media < 0xf8 && ms->ms_media != 0xf0)
                return 1;
 
        /* fat counts(Linux kernel expects at least 1 FAT table) */
-       if (!vs->vs_fats)
+       if (!ms->ms_fats)
+               return 1;
+
+       /*
+        * OS/2 and apparently DFSee will place a FAT12/16-like
+        * pseudo-superblock in the first 512 bytes of non-FAT
+        * filesystems --- at least JFS and HPFS, and possibly others.
+        * So we explicitly check for those filesystems at the
+        * FAT12/16 filesystem magic field identifier, and if they are
+        * present, we rule this out as a FAT filesystem, despite the
+        * FAT-like pseudo-header.
+         */
+       if ((memcmp(ms->ms_magic, "JFS     ", 8) == 0) ||
+           (memcmp(ms->ms_magic, "HPFS    ", 8) == 0))
                return 1;
 
        return probe_fat(probe, id, buf);