From abc67e06783aa1326b99f9ddee820cc495466e6c Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 21 Apr 2010 14:24:52 +0200 Subject: [PATCH] liblkid: export magic strings from raids 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 --- shlibs/blkid/src/superblocks/adaptec_raid.c | 4 +++- shlibs/blkid/src/superblocks/ddf_raid.c | 7 ++++++- shlibs/blkid/src/superblocks/drbd.c | 13 ++++++++++--- shlibs/blkid/src/superblocks/highpoint_raid.c | 3 +++ shlibs/blkid/src/superblocks/isw_raid.c | 4 +++- shlibs/blkid/src/superblocks/jmicron_raid.c | 4 +++- shlibs/blkid/src/superblocks/linux_raid.c | 8 ++++++-- shlibs/blkid/src/superblocks/lsi_raid.c | 4 +++- shlibs/blkid/src/superblocks/nvidia_raid.c | 5 +++-- shlibs/blkid/src/superblocks/promise_raid.c | 7 ++++++- shlibs/blkid/src/superblocks/silicon_raid.c | 7 ++++++- shlibs/blkid/src/superblocks/sysv.c | 14 +++++++++++++- shlibs/blkid/src/superblocks/ufs.c | 8 ++++++++ shlibs/blkid/src/superblocks/via_raid.c | 4 ++++ shlibs/blkid/src/superblocks/zfs.c | 5 +++++ 15 files changed, 82 insertions(+), 15 deletions(-) diff --git a/shlibs/blkid/src/superblocks/adaptec_raid.c b/shlibs/blkid/src/superblocks/adaptec_raid.c index c6b175b4..73b146c6 100644 --- a/shlibs/blkid/src/superblocks/adaptec_raid.c +++ b/shlibs/blkid/src/superblocks/adaptec_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/ddf_raid.c b/shlibs/blkid/src/superblocks/ddf_raid.c index 89bd92c7..a48735d2 100644 --- a/shlibs/blkid/src/superblocks/ddf_raid.c +++ b/shlibs/blkid/src/superblocks/ddf_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/drbd.c b/shlibs/blkid/src/superblocks/drbd.c index 5adcac7b..3490948d 100644 --- a/shlibs/blkid/src/superblocks/drbd.c +++ b/shlibs/blkid/src/superblocks/drbd.c @@ -14,6 +14,7 @@ #include #include #include +#include #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; } diff --git a/shlibs/blkid/src/superblocks/highpoint_raid.c b/shlibs/blkid/src/superblocks/highpoint_raid.c index 111ceb2c..98343c41 100644 --- a/shlibs/blkid/src/superblocks/highpoint_raid.c +++ b/shlibs/blkid/src/superblocks/highpoint_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/isw_raid.c b/shlibs/blkid/src/superblocks/isw_raid.c index 0f4869fd..5149c38a 100644 --- a/shlibs/blkid/src/superblocks/isw_raid.c +++ b/shlibs/blkid/src/superblocks/isw_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/jmicron_raid.c b/shlibs/blkid/src/superblocks/jmicron_raid.c index 70e0e1c6..24430bf9 100644 --- a/shlibs/blkid/src/superblocks/jmicron_raid.c +++ b/shlibs/blkid/src/superblocks/jmicron_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/linux_raid.c b/shlibs/blkid/src/superblocks/linux_raid.c index 0fba6348..6f823f15 100644 --- a/shlibs/blkid/src/superblocks/linux_raid.c +++ b/shlibs/blkid/src/superblocks/linux_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/lsi_raid.c b/shlibs/blkid/src/superblocks/lsi_raid.c index 6baaaa47..3010eb6b 100644 --- a/shlibs/blkid/src/superblocks/lsi_raid.c +++ b/shlibs/blkid/src/superblocks/lsi_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/nvidia_raid.c b/shlibs/blkid/src/superblocks/nvidia_raid.c index 8ce7f12a..e75bec84 100644 --- a/shlibs/blkid/src/superblocks/nvidia_raid.c +++ b/shlibs/blkid/src/superblocks/nvidia_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/promise_raid.c b/shlibs/blkid/src/superblocks/promise_raid.c index 94a64469..1cc70e65 100644 --- a/shlibs/blkid/src/superblocks/promise_raid.c +++ b/shlibs/blkid/src/superblocks/promise_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/silicon_raid.c b/shlibs/blkid/src/superblocks/silicon_raid.c index 2144e505..11277ad6 100644 --- a/shlibs/blkid/src/superblocks/silicon_raid.c +++ b/shlibs/blkid/src/superblocks/silicon_raid.c @@ -15,6 +15,7 @@ #include #include #include +#include #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; } diff --git a/shlibs/blkid/src/superblocks/sysv.c b/shlibs/blkid/src/superblocks/sysv.c index 530e860f..00c8c978 100644 --- a/shlibs/blkid/src/superblocks/sysv.c +++ b/shlibs/blkid/src/superblocks/sysv.c @@ -12,6 +12,7 @@ #include #include #include +#include #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; } } diff --git a/shlibs/blkid/src/superblocks/ufs.c b/shlibs/blkid/src/superblocks/ufs.c index cdce75ef..05bed145 100644 --- a/shlibs/blkid/src/superblocks/ufs.c +++ b/shlibs/blkid/src/superblocks/ufs.c @@ -15,6 +15,7 @@ #include #include #include +#include #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; } diff --git a/shlibs/blkid/src/superblocks/via_raid.c b/shlibs/blkid/src/superblocks/via_raid.c index fc974a70..58650454 100644 --- a/shlibs/blkid/src/superblocks/via_raid.c +++ b/shlibs/blkid/src/superblocks/via_raid.c @@ -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; } diff --git a/shlibs/blkid/src/superblocks/zfs.c b/shlibs/blkid/src/superblocks/zfs.c index 1bf17eba..af5264d4 100644 --- a/shlibs/blkid/src/superblocks/zfs.c +++ b/shlibs/blkid/src/superblocks/zfs.c @@ -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; } -- 2.39.5