Upload Tizen:Base source
[framework/base/util-linux-ng.git] / shlibs / blkid / src / probers / zfs.c
1 /*
2  * Copyright (C) 2009 by Andreas Dilger <adilger@sun.com>
3  *
4  * This file may be redistributed under the terms of the
5  * GNU Lesser General Public License.
6  */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <string.h>
12 #include <errno.h>
13 #include <ctype.h>
14 #include <inttypes.h>
15
16 #include "blkidP.h"
17
18 /* #include <sys/uberblock_impl.h> */
19 #define UBERBLOCK_MAGIC         0x00bab10c              /* oo-ba-bloc!  */
20 struct zfs_uberblock {
21         uint64_t        ub_magic;       /* UBERBLOCK_MAGIC              */
22         uint64_t        ub_version;     /* SPA_VERSION                  */
23         uint64_t        ub_txg;         /* txg of last sync             */
24         uint64_t        ub_guid_sum;    /* sum of all vdev guids        */
25         uint64_t        ub_timestamp;   /* UTC time of last sync        */
26         /*blkptr_t      ub_rootbp;*/    /* MOS objset_phys_t            */
27 } __attribute__((packed));
28
29 static int probe_zfs(blkid_probe pr, const struct blkid_idmag *mag)
30 {
31         struct zfs_uberblock *ub;
32         int swab_endian;
33         uint64_t spa_version;
34
35         ub = blkid_probe_get_sb(pr, mag, struct zfs_uberblock);
36         if (!ub)
37                 return -1;
38
39         swab_endian = (ub->ub_magic == swab64(UBERBLOCK_MAGIC));
40         spa_version = swab_endian ? swab64(ub->ub_version) : ub->ub_version;
41
42         blkid_probe_sprintf_version(pr, "%" PRIu64, spa_version);
43 #if 0
44         /* read nvpair data for pool name, pool GUID from the MOS, but
45          * unfortunately this is more complex than it could be */
46         blkid_probe_set_label(pr, pool_name, pool_len));
47         blkid_probe_set_uuid(pr, pool_guid);
48 #endif
49         return 0;
50 }
51
52 const struct blkid_idinfo zfs_idinfo =
53 {
54         .name           = "zfs",
55         .usage          = BLKID_USAGE_FILESYSTEM,
56         .probefunc      = probe_zfs,
57         .magics         =
58         {
59                 { .magic = "\0\0\x02\xf5\xb0\x07\xb1\x0c", .len = 8, .kboff = 8 },
60                 { .magic = "\x1c\xb1\x07\xb0\xf5\x02\0\0", .len = 8, .kboff = 8 },
61                 { .magic = "\0\0\x02\xf5\xb0\x07\xb1\x0c", .len = 8, .kboff = 264 },
62                 { .magic = "\x0c\xb1\x07\xb0\xf5\x02\0\0", .len = 8, .kboff = 264 },
63                 { NULL }
64         }
65 };
66