chiark / gitweb /
[PATCH] udev_volume_id: volume_id version 034
[elogind.git] / extras / volume_id / volume_id / msdos / msdos.c
index 915c1b29170bddeae7442acea1c3849394967cc0..a90b9efc333010a79a371d77eb726cf8ab9b366f 100644 (file)
 #include "../util.h"
 #include "msdos.h"
 
+struct msdos_partition_entry {
+       __u8    boot_ind;
+       __u8    head;
+       __u8    sector;
+       __u8    cyl;
+       __u8    sys_ind;
+       __u8    end_head;
+       __u8    end_sector;
+       __u8    end_cyl;
+       __u32   start_sect;
+       __u32   nr_sects;
+} __attribute__((packed));
+
 #define MSDOS_MAGIC                    "\x55\xaa"
 #define MSDOS_PARTTABLE_OFFSET         0x1be
 #define MSDOS_SIG_OFF                  0x1fe
 
 int volume_id_probe_msdos_part_table(struct volume_id *id, __u64 off)
 {
-       struct msdos_partition_entry {
-               __u8    boot_ind;
-               __u8    head;
-               __u8    sector;
-               __u8    cyl;
-               __u8    sys_ind;
-               __u8    end_head;
-               __u8    end_sector;
-               __u8    end_cyl;
-               __u32   start_sect;
-               __u32   nr_sects;
-       } __attribute__((packed)) *part;
-
        const __u8 *buf;
        int i;
        __u64 poff;
@@ -78,13 +78,16 @@ int volume_id_probe_msdos_part_table(struct volume_id *id, __u64 off)
        __u64 next;
        int limit;
        int empty = 1;
+       struct msdos_partition_entry *part;
        struct volume_id_partition *p;
 
+       dbg("probing at offset %llu", off);
+
        buf = volume_id_get_buffer(id, off, 0x200);
        if (buf == NULL)
                return -1;
 
-       if (strncmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0)
+       if (memcmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0)
                return -1;
 
        /* check flags on all entries for a valid partition table */
@@ -158,7 +161,7 @@ int volume_id_probe_msdos_part_table(struct volume_id *id, __u64 off)
 
                part = (struct msdos_partition_entry*) &buf[MSDOS_PARTTABLE_OFFSET];
 
-               if (strncmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0)
+               if (memcmp(&buf[MSDOS_SIG_OFF], MSDOS_MAGIC, 2) != 0)
                        break;
 
                next = 0;