summaryrefslogtreecommitdiffstats
path: root/libblkid/src
diff options
context:
space:
mode:
Diffstat (limited to 'libblkid/src')
-rw-r--r--libblkid/src/partitions/dos.c7
-rw-r--r--libblkid/src/probe.c19
-rw-r--r--libblkid/src/save.c2
-rw-r--r--libblkid/src/superblocks/drbd.c19
-rw-r--r--libblkid/src/superblocks/ntfs.c24
-rw-r--r--libblkid/src/superblocks/superblocks.h1
-rw-r--r--libblkid/src/superblocks/zfs.c2
-rw-r--r--libblkid/src/verify.c4
8 files changed, 67 insertions, 11 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/probe.c b/libblkid/src/probe.c
index 1ace06a68..ae1fc06d6 100644
--- a/libblkid/src/probe.c
+++ b/libblkid/src/probe.c
@@ -846,10 +846,15 @@ failed:
* @off: begin of probing area
* @size: size of probing area (zero means whole device/file)
*
- * Assigns the device to probe control struct, resets internal buffers and
- * resets the current probing.
+ * Assigns the device to probe control struct, resets internal buffers, resets
+ * the current probing, and close previously associated device (if open by
+ * libblkid).
*
- * Returns: -1 in case of failure, or 0 on success.
+ * If @fd is < 0 than only resets the prober and returns 1. Note that
+ * blkid_reset_probe() keeps the device associated with the prober, but
+ * blkid_probe_set_device() does complete reset.
+ *
+ * Returns: -1 in case of failure, 0 on success and 1 on reset.
*/
int blkid_probe_set_device(blkid_probe pr, int fd,
blkid_loff_t off, blkid_loff_t size)
@@ -864,6 +869,11 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
if ((pr->flags & BLKID_FL_PRIVATE_FD) && pr->fd >= 0)
close(pr->fd);
+ if (pr->disk_probe) {
+ blkid_free_probe(pr->disk_probe);
+ pr->disk_probe = NULL;
+ }
+
pr->flags &= ~BLKID_FL_PRIVATE_FD;
pr->flags &= ~BLKID_FL_TINY_DEV;
pr->flags &= ~BLKID_FL_CDROM_DEV;
@@ -879,6 +889,9 @@ int blkid_probe_set_device(blkid_probe pr, int fd,
pr->wipe_size = 0;
pr->wipe_chain = NULL;
+ if (fd < 0)
+ return 1;
+
#if defined(POSIX_FADV_RANDOM) && defined(HAVE_POSIX_FADVISE)
/* Disable read-ahead */
posix_fadvise(fd, 0, 0, POSIX_FADV_RANDOM);
diff --git a/libblkid/src/save.c b/libblkid/src/save.c
index 21308a9cf..bceaa1139 100644
--- a/libblkid/src/save.c
+++ b/libblkid/src/save.c
@@ -213,7 +213,7 @@ int main(int argc, char **argv)
int ret;
blkid_init_debug(BLKID_DEBUG_ALL);
- if (argc > 2) {
+ if (argc != 2) {
fprintf(stderr, "Usage: %s [filename]\n"
"Test loading/saving a cache (filename)\n", argv[0]);
exit(1);
diff --git a/libblkid/src/superblocks/drbd.c b/libblkid/src/superblocks/drbd.c
index 4ebaf1739..f3601864e 100644
--- a/libblkid/src/superblocks/drbd.c
+++ b/libblkid/src/superblocks/drbd.c
@@ -45,6 +45,13 @@ enum drbd_uuid_index {
UI_EXTENDED_SIZE /* Everything. */
};
+
+/*
+ * Used by libblkid to avoid unnecessary padding at the end of the structs and
+ * too large unused structs in memory.
+ */
+#define DRBD_MD_OFFSET 4096
+
/*
* user/shared/drbdmeta.c
* Minor modifications wrt. types
@@ -63,7 +70,9 @@ struct md_on_disk_08 {
uint32_t bm_bytes_per_bit;
uint32_t reserved_u32[4];
- char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)];
+ /* Unnecessary for libblkid **
+ * char reserved[8 * 512 - (8*(UI_SIZE+3)+4*11)];
+ */
};
/*
@@ -109,7 +118,9 @@ struct meta_data_on_disk_9 {
struct peer_dev_md_on_disk_9 peers[DRBD_PEERS_MAX];
uint64_t history_uuids[HISTORY_UUIDS];
- char padding[0] __attribute__((aligned(4096)));
+ /* Unnecessary for libblkid **
+ * char padding[0] __attribute__((aligned(4096)));
+ */
} __attribute__((packed));
@@ -118,7 +129,7 @@ static int probe_drbd_84(blkid_probe pr)
struct md_on_disk_08 *md;
off_t off;
- off = pr->size - sizeof(*md);
+ off = pr->size - DRBD_MD_OFFSET;
/* Small devices cannot be drbd (?) */
if (pr->size < 0x10000)
@@ -159,7 +170,7 @@ static int probe_drbd_90(blkid_probe pr)
struct meta_data_on_disk_9 *md;
off_t off;
- off = pr->size - sizeof(*md);
+ off = pr->size - DRBD_MD_OFFSET;
/*
* Smaller ones are certainly not DRBD9 devices.
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 */
diff --git a/libblkid/src/superblocks/zfs.c b/libblkid/src/superblocks/zfs.c
index 4d4b46d55..0af14fb65 100644
--- a/libblkid/src/superblocks/zfs.c
+++ b/libblkid/src/superblocks/zfs.c
@@ -58,7 +58,7 @@ struct nvuint64 {
uint32_t nvu_type;
uint32_t nvu_elem;
uint64_t nvu_value;
-};
+} __attribute__((packed));
struct nvlist {
uint32_t nvl_unknown[3];
diff --git a/libblkid/src/verify.c b/libblkid/src/verify.c
index dbc10f254..a78c9f8f2 100644
--- a/libblkid/src/verify.c
+++ b/libblkid/src/verify.c
@@ -184,9 +184,11 @@ blkid_dev blkid_verify(blkid_cache cache, blkid_dev dev)
dev->bid_name, (long long)st.st_rdev, dev->bid_type));
}
- blkid_reset_probe(cache->probe);
+ /* reset prober */
blkid_probe_reset_superblocks_filter(cache->probe);
+ blkid_probe_set_device(cache->probe, -1, 0, 0);
close(fd);
+
return dev;
}