summaryrefslogtreecommitdiffstats
path: root/libs/blkid/src/probers/zfs.c
diff options
context:
space:
mode:
authorAndreas Dilger2009-04-03 11:28:31 +0200
committerKarel Zak2009-04-03 11:28:31 +0200
commit1f4da8d2429d589f1cad1f4be25051ef1e6790e2 (patch)
tree4d8a014a0d8675c7771e3b38402a98936fe98d98 /libs/blkid/src/probers/zfs.c
parentblkid: check idinfo[] index (diff)
downloadkernel-qcow2-util-linux-1f4da8d2429d589f1cad1f4be25051ef1e6790e2.tar.gz
kernel-qcow2-util-linux-1f4da8d2429d589f1cad1f4be25051ef1e6790e2.tar.xz
kernel-qcow2-util-linux-1f4da8d2429d589f1cad1f4be25051ef1e6790e2.zip
blkid: add ZSF support
Signed-off-by: Andreas Dilger <adilger@sun.com> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libs/blkid/src/probers/zfs.c')
-rw-r--r--libs/blkid/src/probers/zfs.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/libs/blkid/src/probers/zfs.c b/libs/blkid/src/probers/zfs.c
new file mode 100644
index 000000000..7d39034f6
--- /dev/null
+++ b/libs/blkid/src/probers/zfs.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2009 by Andreas Dilger <adilger@sun.com>
+ *
+ * This file may be redistributed under the terms of the
+ * GNU Lesser General Public License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#include <inttypes.h>
+
+#include "blkidP.h"
+
+/* #include <sys/uberblock_impl.h> */
+#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 }
+ }
+};
+