summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2019-07-17 12:35:45 +0200
committerKarel Zak2019-07-17 12:35:45 +0200
commitcdb91409674cfb5d94a374b1e3b2bf1869ecfec7 (patch)
tree7dd1cf4095f7931521c6ad0ec80b470e0f141938
parentlibfdisk: don't use FAT as MBR (diff)
downloadkernel-qcow2-util-linux-cdb91409674cfb5d94a374b1e3b2bf1869ecfec7.tar.gz
kernel-qcow2-util-linux-cdb91409674cfb5d94a374b1e3b2bf1869ecfec7.tar.xz
kernel-qcow2-util-linux-cdb91409674cfb5d94a374b1e3b2bf1869ecfec7.zip
libblkid: do not interpret NTFS as MBR
# 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>
-rw-r--r--libblkid/src/partitions/dos.c7
-rw-r--r--libblkid/src/superblocks/ntfs.c24
-rw-r--r--libblkid/src/superblocks/superblocks.h1
3 files changed, 31 insertions, 1 deletions
diff --git a/libblkid/src/partitions/dos.c b/libblkid/src/partitions/dos.c
index 6c1b519f7..f8b0ee50d 100644
--- a/libblkid/src/partitions/dos.c
+++ b/libblkid/src/partitions/dos.c
@@ -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
diff --git a/libblkid/src/superblocks/ntfs.c b/libblkid/src/superblocks/ntfs.c
index 5ea2a454a..90a102f89 100644
--- a/libblkid/src/superblocks/ntfs.c
+++ b/libblkid/src/superblocks/ntfs.c
@@ -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 =
{
diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h
index 3313d0245..59682c86d 100644
--- a/libblkid/src/superblocks/superblocks.h
+++ b/libblkid/src/superblocks/superblocks.h
@@ -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 */