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 <adilger@sun.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Andreas Dilger 2010-02-17 10:21:27 +01:00 committed by Karel Zak
parent 98e9ff610e
commit e54a76ca07
2 changed files with 19 additions and 9 deletions

View File

@ -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 }
}
};

View File

@ -1,3 +1,3 @@
ID_FS_TYPE=zfs
ID_FS_USAGE=filesystem
ID_FS_VERSION=1
ID_FS_VERSION=8