From: Andreas Dilger Date: Fri, 3 Apr 2009 09:28:31 +0000 (+0200) Subject: blkid: add ZSF support X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f4da8d2429d589f1cad1f4be25051ef1e6790e2;p=util-linux blkid: add ZSF support Signed-off-by: Andreas Dilger Signed-off-by: Karel Zak --- diff --git a/libs/blkid/src/probe.c b/libs/blkid/src/probe.c index 604c7eba..74c9edfc 100644 --- a/libs/blkid/src/probe.c +++ b/libs/blkid/src/probe.c @@ -67,7 +67,7 @@ static const struct blkid_idinfo *idinfos[] = &jfs_idinfo, &udf_idinfo, &iso9660_idinfo, - /* TODO: zfs */ + &zfs_idinfo, &hfsplus_idinfo, &hfs_idinfo, &ufs_idinfo, diff --git a/libs/blkid/src/probers/Makefile.am b/libs/blkid/src/probers/Makefile.am index 2f5a79da..d8a98ed2 100644 --- a/libs/blkid/src/probers/Makefile.am +++ b/libs/blkid/src/probers/Makefile.am @@ -39,4 +39,5 @@ libblkid_probers_la_SOURCES = \ netware.c \ sysv.c \ btrfs.c \ - lvm.c + lvm.c \ + zfs.c diff --git a/libs/blkid/src/probers/probers.h b/libs/blkid/src/probers/probers.h index 0a9a070f..c3b22774 100644 --- a/libs/blkid/src/probers/probers.h +++ b/libs/blkid/src/probers/probers.h @@ -55,5 +55,6 @@ extern const struct blkid_idinfo netware_idinfo; extern const struct blkid_idinfo sysv_idinfo; extern const struct blkid_idinfo xenix_idinfo; extern const struct blkid_idinfo btrfs_idinfo; +extern const struct blkid_idinfo zfs_idinfo; #endif /* _BLKID_PROBE_H */ diff --git a/libs/blkid/src/probers/zfs.c b/libs/blkid/src/probers/zfs.c new file mode 100644 index 00000000..7d39034f --- /dev/null +++ b/libs/blkid/src/probers/zfs.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009 by Andreas Dilger + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "blkidP.h" + +/* #include */ +#define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */ +struct zfs_uberblock { + uint64_t ub_magic; /* UBERBLOCK_MAGIC */ + uint64_t ub_version; /* SPA_VERSION */ + 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 */ +}; + +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; + + blkid_probe_sprintf_version(pr, "%" PRIu64, spa_version); +#if 0 + /* read nvpair data for pool name, pool GUID from the MOS, but + * unfortunately this is more complex than it could be */ + blkid_probe_set_label(pr, pool_name, pool_len)); + blkid_probe_set_uuid(pr, pool_guid); +#endif + return 0; +} + +const struct blkid_idinfo zfs_idinfo = +{ + .name = "zfs", + .usage = BLKID_USAGE_FILESYSTEM, + .probefunc = probe_zfs, + .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 }, + { NULL } + } +}; +