]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: vfat: Change parsing label in special cases
authorPali Rohár <pali.rohar@gmail.com>
Sat, 25 Nov 2017 11:48:18 +0000 (12:48 +0100)
committerPali Rohár <pali.rohar@gmail.com>
Sat, 25 Nov 2017 11:48:18 +0000 (12:48 +0100)
* Use only label from the root directory and do not fallback to the label
  stored in boot sector. This is how MS-DOS 6.22, MS-DOS 7.10, Windows 98,
  Windows XP and also Windows 10 behave. Moreover Windows XP and Windows 10
  do not touch label in boot sector anymore, so removing FAT label on those
  Windowses leads to having old label still stored in boot sector (which
  MS-DOS and Windows fully ignore).

* Label entry "NO NAME" in root directory is treated as label "NO NAME"
  instead of empty label. In root directory it has no special meaning.
  String "NO NAME" has a special meaning (empty label) only for label
  stored in boot sector.

* Label from the boot sector is now stored into LABEL_FATBOOT field. So if
  there are applications which depends or needs to read this label, they
  have ability.

After this change LABEL always correspondent to the label from the root
directory and LABEL_FATBOOT to the label stored in the boot sector. If some
of those labels is missing or is not present (e.g. "NO LABEL" in boot
sector) then particular field is not set.

Signed-off-by: Pali Rohár <pali.rohar@gmail.com>
libblkid/src/superblocks/vfat.c

index 3aeba018aaa216826a29d55682a581db38f13214..df4ebe3711c89e6f776679a636fa2cddb4da0b95 100644 (file)
@@ -308,6 +308,7 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
        struct vfat_super_block *vs;
        struct msdos_super_block *ms;
        const unsigned char *vol_label = NULL;
+       const unsigned char *boot_label = NULL;
        unsigned char *vol_serno = NULL, vol_label_buf[11];
        uint16_t sector_size = 0, reserved;
        uint32_t cluster_count, fat_size;
@@ -338,8 +339,7 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
                        vol_label = vol_label_buf;
                }
 
-               if (!vol_label || !memcmp(vol_label, no_name, 11))
-                       vol_label = ms->ms_label;
+               boot_label = ms->ms_label;
                vol_serno = ms->ms_serno;
 
                blkid_probe_set_value(pr, "SEC_TYPE", (unsigned char *) "msdos",
@@ -393,8 +393,7 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
 
                version = "FAT32";
 
-               if (!vol_label || !memcmp(vol_label, no_name, 11))
-                       vol_label = vs->vs_label;
+               boot_label = vs->vs_label;
                vol_serno = vs->vs_serno;
 
                /*
@@ -423,7 +422,10 @@ static int probe_vfat(blkid_probe pr, const struct blkid_idmag *mag)
                }
        }
 
-       if (vol_label && memcmp(vol_label, no_name, 11))
+       if (boot_label && memcmp(boot_label, no_name, 11))
+               blkid_probe_set_id_label(pr, "LABEL_FATBOOT", (unsigned char *) boot_label, 11);
+
+       if (vol_label)
                blkid_probe_set_label(pr, (unsigned char *) vol_label, 11);
 
        /* We can't just print them as %04X, because they are unaligned */