]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: do not interpret NTFS as MBR
authorKarel Zak <kzak@redhat.com>
Wed, 17 Jul 2019 10:35:45 +0000 (12:35 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 17 Jul 2019 10:35:45 +0000 (12:35 +0200)
 # mkntfs -Q -F /dev/sdc

old version:
 # ./blkid -p /dev/sdc
 /dev/sdc: UUID="0E9E8C5F2F718479" TYPE="ntfs" USAGE="filesystem" PTTYPE="dos"

new version:
 # ./blkid -p /dev/sdc
 /dev/sdc: UUID="0E9E8C5F2F718479" TYPE="ntfs" USAGE="filesystem"

Reported-by: Mike Fleetwood <mike.fleetwood@googlemail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/partitions/dos.c
libblkid/src/superblocks/ntfs.c
libblkid/src/superblocks/superblocks.h

index 6c1b519f79c4ee13dc5ec1ceb4a26cc51f26ffe1..f8b0ee50d69d7e0227a6c91d8a0b69cfcb094fdb 100644 (file)
@@ -14,6 +14,7 @@
 #include <stdint.h>
 
 #include "partitions.h"
+#include "superblocks/superblocks.h"
 #include "aix.h"
 
 /* see superblocks/vfat.c */
@@ -222,6 +223,12 @@ static int probe_dos_pt(blkid_probe pr,
                goto nothing;
        }
 
+       /* Another false possitive is NTFS */
+       if (blkid_probe_is_ntfs(pr) == 1) {
+               DBG(LOWPROBE, ul_debug("probably NTFS -- ignore"));
+               goto nothing;
+       }
+
        /*
         * Ugly exception, if the device contains a valid LVM physical volume
         * and empty MBR (=no partition defined) then it's LVM and MBR should
index 5ea2a454a91efa05e296252dd69ffd69757e9450..90a102f89ef671a98ff18d875bbaf2ad89dc03b8 100644 (file)
@@ -78,7 +78,7 @@ struct file_attribute {
 #define        MFT_RECORD_ATTR_VOLUME_NAME     0x60
 #define        MFT_RECORD_ATTR_END             0xffffffff
 
-static int probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag)
+static int __probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag, int save_info)
 {
        struct ntfs_super_block *ns;
        struct master_file_table_record *mft;
@@ -174,6 +174,10 @@ static int probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag)
        if (memcmp(buf_mft, "FILE", 4))
                return 1;
 
+       /* return if caller does not care about UUID and LABEL */
+       if (!save_info)
+               return 0;
+
        mft = (struct master_file_table_record *) buf_mft;
        attr_off = le16_to_cpu(mft->attrs_offset);
 
@@ -211,6 +215,24 @@ static int probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag)
        return 0;
 }
 
+static int probe_ntfs(blkid_probe pr, const struct blkid_idmag *mag)
+{
+       return __probe_ntfs(pr, mag, 1);
+}
+
+int blkid_probe_is_ntfs(blkid_probe pr)
+{
+       const struct blkid_idmag *mag = NULL;
+       int rc;
+
+       rc = blkid_probe_get_idmag(pr, &ntfs_idinfo, NULL, &mag);
+       if (rc < 0)
+               return rc;      /* error */
+       if (rc != BLKID_PROBE_OK || !mag)
+               return 0;
+
+       return __probe_ntfs(pr, mag, 0) == 0 ? 1 : 0;
+}
 
 const struct blkid_idinfo ntfs_idinfo =
 {
index 3313d02454ed2079a7c3d771c3ab9432f259f769..59682c86d37b0da71c62465470803dc34e5ca45a 100644 (file)
@@ -109,5 +109,6 @@ extern int blkid_probe_set_utf8_id_label(blkid_probe pr, const char *name,
                             const unsigned char *data, size_t len, int enc);
 
 extern int blkid_probe_is_bitlocker(blkid_probe pr);
+extern int blkid_probe_is_ntfs(blkid_probe pr);
 
 #endif /* _BLKID_SUPERBLOCKS_H */