2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
5 * GRUB is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
22 #ifndef GRUB_ZFS_HEADER
23 #define GRUB_ZFS_HEADER 1
26 #include <grub/disk.h>
27 #include <grub/crypto.h>
29 typedef enum grub_zfs_endian
31 GRUB_ZFS_UNKNOWN_ENDIAN
= -2,
32 GRUB_ZFS_LITTLE_ENDIAN
= -1,
33 GRUB_ZFS_BIG_ENDIAN
= 0
37 * On-disk version number.
39 #define SPA_VERSION_INITIAL 1ULL
40 #define SPA_VERSION_BEFORE_FEATURES 33ULL
41 #define SPA_VERSION_FEATURES 5000ULL
42 #define SPA_VERSION_IS_SUPPORTED(v) \
43 (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
44 ((v) == SPA_VERSION_FEATURES))
46 * The following are configuration names used in the nvlist describing a pool's
49 #define ZPOOL_CONFIG_VERSION "version"
50 #define ZPOOL_CONFIG_POOL_NAME "name"
51 #define ZPOOL_CONFIG_POOL_STATE "state"
52 #define ZPOOL_CONFIG_POOL_TXG "txg"
53 #define ZPOOL_CONFIG_POOL_GUID "pool_guid"
54 #define ZPOOL_CONFIG_CREATE_TXG "create_txg"
55 #define ZPOOL_CONFIG_TOP_GUID "top_guid"
56 #define ZPOOL_CONFIG_VDEV_TREE "vdev_tree"
57 #define ZPOOL_CONFIG_TYPE "type"
58 #define ZPOOL_CONFIG_CHILDREN "children"
59 #define ZPOOL_CONFIG_ID "id"
60 #define ZPOOL_CONFIG_GUID "guid"
61 #define ZPOOL_CONFIG_PATH "path"
62 #define ZPOOL_CONFIG_DEVID "devid"
63 #define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array"
64 #define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift"
65 #define ZPOOL_CONFIG_ASHIFT "ashift"
66 #define ZPOOL_CONFIG_ASIZE "asize"
67 #define ZPOOL_CONFIG_DTL "DTL"
68 #define ZPOOL_CONFIG_STATS "stats"
69 #define ZPOOL_CONFIG_WHOLE_DISK "whole_disk"
70 #define ZPOOL_CONFIG_ERRCOUNT "error_count"
71 #define ZPOOL_CONFIG_NOT_PRESENT "not_present"
72 #define ZPOOL_CONFIG_SPARES "spares"
73 #define ZPOOL_CONFIG_IS_SPARE "is_spare"
74 #define ZPOOL_CONFIG_NPARITY "nparity"
75 #define ZPOOL_CONFIG_PHYS_PATH "phys_path"
76 #define ZPOOL_CONFIG_L2CACHE "l2cache"
77 #define ZPOOL_CONFIG_HOLE_ARRAY "hole_array"
78 #define ZPOOL_CONFIG_VDEV_CHILDREN "vdev_children"
79 #define ZPOOL_CONFIG_IS_HOLE "is_hole"
80 #define ZPOOL_CONFIG_DDT_HISTOGRAM "ddt_histogram"
81 #define ZPOOL_CONFIG_DDT_OBJ_STATS "ddt_object_stats"
82 #define ZPOOL_CONFIG_DDT_STATS "ddt_stats"
83 #define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read"
85 * The persistent vdev state is stored as separate values rather than a single
86 * 'vdev_state' entry. This is because a device can be in multiple states, such
87 * as offline and degraded.
89 #define ZPOOL_CONFIG_OFFLINE "offline"
90 #define ZPOOL_CONFIG_FAULTED "faulted"
91 #define ZPOOL_CONFIG_DEGRADED "degraded"
92 #define ZPOOL_CONFIG_REMOVED "removed"
94 #define VDEV_TYPE_ROOT "root"
95 #define VDEV_TYPE_MIRROR "mirror"
96 #define VDEV_TYPE_REPLACING "replacing"
97 #define VDEV_TYPE_RAIDZ "raidz"
98 #define VDEV_TYPE_DISK "disk"
99 #define VDEV_TYPE_FILE "file"
100 #define VDEV_TYPE_MISSING "missing"
101 #define VDEV_TYPE_HOLE "hole"
102 #define VDEV_TYPE_SPARE "spare"
103 #define VDEV_TYPE_L2CACHE "l2cache"
106 * pool state. The following states are written to disk as part of the normal
107 * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE. The remaining
108 * states are software abstractions used at various levels to communicate pool
111 typedef enum pool_state
{
112 POOL_STATE_ACTIVE
= 0, /* In active use */
113 POOL_STATE_EXPORTED
, /* Explicitly exported */
114 POOL_STATE_DESTROYED
, /* Explicitly destroyed */
115 POOL_STATE_SPARE
, /* Reserved for hot spare use */
116 POOL_STATE_L2CACHE
, /* Level 2 ARC device */
117 POOL_STATE_UNINITIALIZED
, /* Internal spa_t state */
118 POOL_STATE_UNAVAIL
, /* Internal libzfs state */
119 POOL_STATE_POTENTIALLY_ACTIVE
/* Internal libzfs state */
122 struct grub_zfs_data
;
124 grub_err_t
grub_zfs_fetch_nvlist (grub_device_t dev
, char **nvlist
);
125 grub_err_t
grub_zfs_getmdnobj (grub_device_t dev
, const char *fsfilename
,
126 grub_uint64_t
*mdnobj
);
128 char *grub_zfs_nvlist_lookup_string (const char *nvlist
, const char *name
);
129 char *grub_zfs_nvlist_lookup_nvlist (const char *nvlist
, const char *name
);
130 int grub_zfs_nvlist_lookup_uint64 (const char *nvlist
, const char *name
,
132 char *grub_zfs_nvlist_lookup_nvlist_array (const char *nvlist
,
134 grub_size_t array_index
);
135 int grub_zfs_nvlist_lookup_nvlist_array_get_nelm (const char *nvlist
,
138 grub_zfs_add_key (grub_uint8_t
*key_in
,
142 extern grub_err_t (*grub_zfs_decrypt
) (grub_crypto_cipher_handle_t cipher
,
145 char *buf
, grub_size_t size
,
146 const grub_uint32_t
*expected_mac
,
147 grub_zfs_endian_t endian
);
151 extern grub_crypto_cipher_handle_t (*grub_zfs_load_key
) (const struct grub_zfs_key
*key
,
158 #endif /* ! GRUB_ZFS_HEADER */