From: Andreas Dilger Date: Wed, 17 Feb 2010 09:21:27 +0000 (+0100) Subject: libblkid: fix ZSF detection X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00edcf5543b2fd402a2e2981266d714bdaef7098;p=util-linux libblkid: fix ZSF detection Fix the ZFS device detection by looking at multiple uberblocks to see if any are present, rather than looking for the ZFS boot block which is not always present. There may be up to 128 uberblocks, but the first 4 are not written to disk on a newly-formatted filesystem so check several of them at different offsets within the uberblock array. [kzak@redhat.com: - port e2fsprogs patch to util-linux-ng] Signed-off-by: Andreas Dilger Signed-off-by: Karel Zak --- diff --git a/shlibs/blkid/src/superblocks/zfs.c b/shlibs/blkid/src/superblocks/zfs.c index 0f580262..3ee93696 100644 --- a/shlibs/blkid/src/superblocks/zfs.c +++ b/shlibs/blkid/src/superblocks/zfs.c @@ -23,21 +23,22 @@ struct zfs_uberblock { uint64_t ub_txg; /* txg of last sync */ uint64_t ub_guid_sum; /* sum of all vdev guids */ uint64_t ub_timestamp; /* UTC time of last sync */ - /*blkptr_t ub_rootbp;*/ /* MOS objset_phys_t */ + char ub_rootbp; /* MOS objset_phys_t */ } __attribute__((packed)); static int probe_zfs(blkid_probe pr, const struct blkid_idmag *mag) { struct zfs_uberblock *ub; - int swab_endian; uint64_t spa_version; ub = blkid_probe_get_sb(pr, mag, struct zfs_uberblock); if (!ub) return -1; - swab_endian = (ub->ub_magic == swab64(UBERBLOCK_MAGIC)); - spa_version = swab_endian ? swab64(ub->ub_version) : ub->ub_version; + if (ub->ub_magic == be64_to_cpu(UBERBLOCK_MAGIC)) + spa_version = be64_to_cpu(ub->ub_version); + else + spa_version = le64_to_cpu(ub->ub_version); blkid_probe_sprintf_version(pr, "%" PRIu64, spa_version); #if 0 @@ -57,10 +58,19 @@ const struct blkid_idinfo zfs_idinfo = .minsz = 64 * 1024 * 1024, .magics = { - { .magic = "\0\0\x02\xf5\xb0\x07\xb1\x0c", .len = 8, .kboff = 8 }, - { .magic = "\x1c\xb1\x07\xb0\xf5\x02\0\0", .len = 8, .kboff = 8 }, - { .magic = "\0\0\x02\xf5\xb0\x07\xb1\x0c", .len = 8, .kboff = 264 }, - { .magic = "\x0c\xb1\x07\xb0\xf5\x02\0\0", .len = 8, .kboff = 264 }, + /* ZFS has 128 root blocks (#4 is the first used), check only 6 of them */ + { .magic = "\0\0\0\0\0\xba\xb1\x0c", .len = 8, .kboff = 128 }, + { .magic = "\x0c\xb1\xba\0\0\0\0\0", .len = 8, .kboff = 128 }, + { .magic = "\0\0\0\0\0\xba\xb1\x0c", .len = 8, .kboff = 132 }, + { .magic = "\x0c\xb1\xba\0\0\0\0\0", .len = 8, .kboff = 132 }, + { .magic = "\0\0\0\0\0\xba\xb1\x0c", .len = 8, .kboff = 136 }, + { .magic = "\x0c\xb1\xba\0\0\0\0\0", .len = 8, .kboff = 136 }, + { .magic = "\0\0\0\0\0\xba\xb1\x0c", .len = 8, .kboff = 384 }, + { .magic = "\x0c\xb1\xba\0\0\0\0\0", .len = 8, .kboff = 384 }, + { .magic = "\0\0\0\0\0\xba\xb1\x0c", .len = 8, .kboff = 388 }, + { .magic = "\x0c\xb1\xba\0\0\0\0\0", .len = 8, .kboff = 388 }, + { .magic = "\0\0\0\0\0\xba\xb1\x0c", .len = 8, .kboff = 392 }, + { .magic = "\x0c\xb1\xba\0\0\0\0\0", .len = 8, .kboff = 392 }, { NULL } } }; diff --git a/tests/expected/blkid/low-probe-zfs b/tests/expected/blkid/low-probe-zfs index 94cec8b3..8159f18c 100644 --- a/tests/expected/blkid/low-probe-zfs +++ b/tests/expected/blkid/low-probe-zfs @@ -1,3 +1,3 @@ ID_FS_TYPE=zfs ID_FS_USAGE=filesystem -ID_FS_VERSION=1 +ID_FS_VERSION=8