]> err.no Git - util-linux/commitdiff
liblkid: export magic strings from raids
authorKarel Zak <kzak@redhat.com>
Wed, 21 Apr 2010 12:24:52 +0000 (14:24 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 21 Apr 2010 13:49:59 +0000 (15:49 +0200)
The library provides detected magic strings by SBMAGIC= and offsets of
the magic strings by SBMAGIC_OFFSET= variables. This patch allows to
support this feature for RAIDs and filesystems where the magic string
is not on fixed position.

Signed-off-by: Karel Zak <kzak@redhat.com>
15 files changed:
shlibs/blkid/src/superblocks/adaptec_raid.c
shlibs/blkid/src/superblocks/ddf_raid.c
shlibs/blkid/src/superblocks/drbd.c
shlibs/blkid/src/superblocks/highpoint_raid.c
shlibs/blkid/src/superblocks/isw_raid.c
shlibs/blkid/src/superblocks/jmicron_raid.c
shlibs/blkid/src/superblocks/linux_raid.c
shlibs/blkid/src/superblocks/lsi_raid.c
shlibs/blkid/src/superblocks/nvidia_raid.c
shlibs/blkid/src/superblocks/promise_raid.c
shlibs/blkid/src/superblocks/silicon_raid.c
shlibs/blkid/src/superblocks/sysv.c
shlibs/blkid/src/superblocks/ufs.c
shlibs/blkid/src/superblocks/via_raid.c
shlibs/blkid/src/superblocks/zfs.c

index c6b175b44a5ac1bbbc393c8e75c423de26d0c77d..73b146c6a737a32475cb0a6d991e377a960e6cf1 100644 (file)
@@ -94,7 +94,9 @@ static int probe_adraid(blkid_probe pr, const struct blkid_idmag *mag)
                return -1;
        if (blkid_probe_sprintf_version(pr, "%u", ad->resver) != 0)
                return -1;
-
+       if (blkid_probe_set_magic(pr, off, sizeof(ad->b0idcode),
+                               (unsigned char *) &ad->b0idcode))
+               return -1;
        return 0;
 }
 
index 89bd92c7a00753d341d9fada9aa322196201f0de..a48735d2a358e4f5d39772cec28069c40a8b8c17 100644 (file)
@@ -32,12 +32,13 @@ static int probe_ddf(blkid_probe pr, const struct blkid_idmag *mag)
        int i;
        struct ddf_header *ddf = NULL;
        char version[DDF_REV_LENGTH + 1];
+       uint64_t off;
 
        if (pr->size < 0x30000)
                return -1;
 
        for (i = 0; i < ARRAY_SIZE(hdrs); i++) {
-               uint64_t off = ((pr->size / 0x200) - hdrs[i]) * 0x200;
+               off = ((pr->size / 0x200) - hdrs[i]) * 0x200;
 
                ddf = (struct ddf_header *) blkid_probe_get_buffer(pr,
                                        off,
@@ -61,6 +62,10 @@ static int probe_ddf(blkid_probe pr, const struct blkid_idmag *mag)
 
        if (blkid_probe_set_version(pr, version) != 0)
                return -1;
+       if (blkid_probe_set_magic(pr, off,
+                       sizeof(ddf->signature),
+                       (unsigned char *) ddf->signature))
+               return -1;
        return 0;
 }
 
index 5adcac7b92926a94ee4668768f2b07e87c2a8732..3490948de3e712fbe128e250c82eab73b5b89016 100644 (file)
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <inttypes.h>
+#include <stddef.h>
 
 #include "superblocks.h"
 
@@ -75,9 +76,9 @@ static int probe_drbd(blkid_probe pr, const struct blkid_idmag *mag)
                return -1;
 
        md = (struct md_on_disk_08 *)
-               blkid_probe_get_buffer(pr,
-               off,
-               sizeof(struct md_on_disk_08));
+                       blkid_probe_get_buffer(pr,
+                                       off,
+                                       sizeof(struct md_on_disk_08));
        if (!md)
                return -1;
 
@@ -94,6 +95,12 @@ static int probe_drbd(blkid_probe pr, const struct blkid_idmag *mag)
 
        blkid_probe_set_version(pr, "v08");
 
+       if (blkid_probe_set_magic(pr,
+                               off + offsetof(struct md_on_disk_08, magic),
+                               sizeof(md->magic),
+                               (unsigned char *) &md->magic))
+               return -1;
+
        return 0;
 }
 
index 111ceb2cc7c61fb28101f4bd7eb07e3f88814802..98343c418d30c54cb5553070e6909e39eafb3963 100644 (file)
@@ -41,6 +41,9 @@ static int probe_highpoint45x(blkid_probe pr, const struct blkid_idmag *mag)
        magic = le32_to_cpu(hpt->magic);
        if (magic != HPT45X_MAGIC_OK && magic != HPT45X_MAGIC_BAD)
                return -1;
+       if (blkid_probe_set_magic(pr, off, sizeof(hpt->magic),
+                               (unsigned char *) &hpt->magic))
+               return -1;
        return 0;
 }
 
index 0f4869fdca0b032561e3c060b9979347ef4cde77..5149c38a347b26f71d2d73920b3ca96f64a7f112 100644 (file)
@@ -46,7 +46,9 @@ static int probe_iswraid(blkid_probe pr, const struct blkid_idmag *mag)
        if (blkid_probe_sprintf_version(pr, "%6s",
                        &isw->sig[sizeof(ISW_SIGNATURE)-1]) != 0)
                return -1;
-
+       if (blkid_probe_set_magic(pr, off, sizeof(isw->sig),
+                               (unsigned char *) isw->sig))
+               return -1;
        return 0;
 }
 
index 70e0e1c60e97a5cf71040a1aacf270b0c777dfde..24430bf99da196e7f0e36501abc13de3502fc883 100644 (file)
@@ -45,7 +45,9 @@ static int probe_jmraid(blkid_probe pr, const struct blkid_idmag *mag)
        if (blkid_probe_sprintf_version(pr, "%u.%u",
                                jm->major_version, jm->minor_version) != 0)
                return -1;
-
+       if (blkid_probe_set_magic(pr, off, sizeof(jm->signature),
+                               (unsigned char *) jm->signature))
+               return -1;
        return 0;
 }
 
index 0fba6348985f811a304ac15d049c08f43b9022c0..6f823f15c27c9fa653947195f5eab2fbe566731e 100644 (file)
@@ -95,7 +95,9 @@ static int probe_raid0(blkid_probe pr, off_t off)
 
        if (blkid_probe_set_uuid(pr, (unsigned char *) uuid.bytes) != 0)
                return -1;
-
+       if (blkid_probe_set_magic(pr, off, sizeof(mdp0->md_magic),
+                               (unsigned char *) &mdp0->md_magic))
+               return -1;
        return 0;
 }
 
@@ -118,7 +120,9 @@ static int probe_raid1(blkid_probe pr, off_t off)
        if (blkid_probe_set_label(pr, mdp1->set_name,
                                sizeof(mdp1->set_name)) != 0)
                return -1;
-
+       if (blkid_probe_set_magic(pr, off, sizeof(mdp1->magic),
+                               (unsigned char *) &mdp1->magic))
+               return -1;
        return 0;
 }
 
index 6baaaa4770ad94c093d461ab076654902551f116..3010eb6b73d4298e66131d30ec072810f471a83d 100644 (file)
@@ -41,7 +41,9 @@ static int probe_lsiraid(blkid_probe pr, const struct blkid_idmag *mag)
 
        if (memcmp(lsi->sig, LSI_SIGNATURE, sizeof(LSI_SIGNATURE)-1) != 0)
                return -1;
-
+       if (blkid_probe_set_magic(pr, off, sizeof(lsi->sig),
+                               (unsigned char *) lsi->sig))
+               return -1;
        return 0;
 }
 
index 8ce7f12a37938779fa2cfcfb1d197542f26031f2..e75bec848bc1bec073a3c72f7226944be7570214 100644 (file)
@@ -43,10 +43,11 @@ static int probe_nvraid(blkid_probe pr, const struct blkid_idmag *mag)
 
        if (memcmp(nv->vendor, NVIDIA_SIGNATURE, sizeof(NVIDIA_SIGNATURE)-1) != 0)
                return -1;
-
        if (blkid_probe_sprintf_version(pr, "%u", le16_to_cpu(nv->version)) != 0)
                return -1;
-
+       if (blkid_probe_set_magic(pr, off, sizeof(nv->vendor),
+                               (unsigned char *) nv->vendor))
+               return -1;
        return 0;
 }
 
index 94a64469f917a0848d9bca516f3fd8dc2fa14961..1cc70e65e9a5c5fc366e5c8bd25cda7783996580 100644 (file)
@@ -47,8 +47,13 @@ static int probe_pdcraid(blkid_probe pr, const struct blkid_idmag *mag)
                        return -1;
 
                if (memcmp(pdc->sig, PDC_SIGNATURE,
-                               sizeof(PDC_SIGNATURE) - 1) == 0)
+                               sizeof(PDC_SIGNATURE) - 1) == 0) {
+
+                       if (blkid_probe_set_magic(pr, off, sizeof(pdc->sig),
+                                               (unsigned char *) pdc->sig))
+                               return -1;
                        return 0;
+               }
        }
        return -1;
 }
index 2144e5052bc0f421462fade7260273391dc34984..11277ad6973c2bf275d4acb10e8bc8c1636acff8 100644 (file)
@@ -15,6 +15,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <stdint.h>
+#include <stddef.h>
 
 #include "superblocks.h"
 
@@ -63,7 +64,11 @@ static int probe_silraid(blkid_probe pr, const struct blkid_idmag *mag)
                                le16_to_cpu(sil->major_ver),
                                le16_to_cpu(sil->minor_ver)) != 0)
                return -1;
-
+       if (blkid_probe_set_magic(pr,
+                       off + offsetof(struct silicon_metadata, magic),
+                       sizeof(sil->magic),
+                       (unsigned char *) &sil->magic))
+               return -1;
        return 0;
 }
 
index 530e860f08e354e4c0085e6646b4a394e98dfeb3..00c8c978b5c2edd6e0c373472bc46f5277edaf76 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdint.h>
+#include <stddef.h>
 
 #include "superblocks.h"
 
@@ -107,7 +108,18 @@ static int probe_sysv(blkid_probe pr, const struct blkid_idmag *mag)
 
                if (sb->s_magic == cpu_to_le32(0xfd187e20) ||
                    sb->s_magic == cpu_to_be32(0xfd187e20)) {
-                       blkid_probe_set_label(pr, sb->s_fname, sizeof(sb->s_fname));
+
+                       if (blkid_probe_set_label(pr, sb->s_fname,
+                                               sizeof(sb->s_fname)))
+                               return -1;
+
+                       if (blkid_probe_set_magic(pr,
+                                       off + offsetof(struct sysv_super_block,
+                                                               s_magic),
+                                       sizeof(sb->s_magic),
+                                       (unsigned char *) &sb->s_magic))
+                               return -1;
+
                        return 0;
                }
        }
index cdce75ef4c9d04074069597ff90f7c392d052643..05bed1451373f6dc1cc4dcc899f58752c95d15a3 100644 (file)
@@ -15,6 +15,7 @@
 #include <errno.h>
 #include <ctype.h>
 #include <stdint.h>
+#include <stddef.h>
 
 #include "superblocks.h"
 
@@ -205,6 +206,13 @@ found:
        } else
                blkid_probe_set_version(pr, "1");
 
+       if (blkid_probe_set_magic(pr,
+                       (offsets[i] * 1024) +
+                               offsetof(struct ufs_super_block, fs_magic),
+                       sizeof(ufs->fs_magic),
+                       (unsigned char *) &ufs->fs_magic))
+               return -1;
+
        return 0;
 }
 
index fc974a701a8d775e79a700d8e7415a236c2dda42..5865045464747571a12169726655af7f9fed41a5 100644 (file)
@@ -69,6 +69,10 @@ static int probe_viaraid(blkid_probe pr, const struct blkid_idmag *mag)
                return -1;
        if (blkid_probe_sprintf_version(pr, "%u", v->version_number) != 0)
                return -1;
+       if (blkid_probe_set_magic(pr, off,
+                               sizeof(v->signature),
+                               (unsigned char *) &v->signature))
+               return -1;
        return 0;
 }
 
index 1bf17ebad3cae46a3b80d6ae628e13eb8c9d047b..af5264d46207a136482a0ea66918fcc0332f8478 100644 (file)
@@ -203,6 +203,11 @@ static int probe_zfs(blkid_probe pr, const struct blkid_idmag *mag)
 
        zfs_extract_guid_name(pr, offset);
 
+       if (blkid_probe_set_magic(pr, offset,
+                               sizeof(ub->ub_magic),
+                               (unsigned char *) &ub->ub_magic))
+               return -1;
+
        return 0;
 }