]> err.no Git - util-linux/commitdiff
blkid: add ZSF support
authorAndreas Dilger <adilger@sun.com>
Fri, 3 Apr 2009 09:28:31 +0000 (11:28 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 3 Apr 2009 09:28:31 +0000 (11:28 +0200)
Signed-off-by: Andreas Dilger <adilger@sun.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
libs/blkid/src/probe.c
libs/blkid/src/probers/Makefile.am
libs/blkid/src/probers/probers.h
libs/blkid/src/probers/zfs.c [new file with mode: 0644]

index 604c7ebab4361cf816b143f64527e15457543b5b..74c9edfcbaba7ed0900b98be5d763034c323efc7 100644 (file)
@@ -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,
index 2f5a79dac6e69b6941df7935df77e9b0ce2616ab..d8a98ed2484a3a040ac57f3e072d03b588c714e2 100644 (file)
@@ -39,4 +39,5 @@ libblkid_probers_la_SOURCES = \
                        netware.c \
                        sysv.c \
                        btrfs.c \
-                       lvm.c
+                       lvm.c \
+                       zfs.c
index 0a9a070fcb9e9b2b50658df3575a6834c152a040..c3b227743ddd6fb08658c2b4f22156a2df23ea3d 100644 (file)
@@ -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 (file)
index 0000000..7d39034
--- /dev/null
@@ -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 }
+       }
+};
+