1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  *  GRUB  --  GRand Unified Bootloader
4  *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
5  */
6 /*
7  * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
8  */
9 
10 #ifndef	GRUB_ZFS_HEADER
11 #define	GRUB_ZFS_HEADER 1
12 
13 
14 /*
15  * On-disk version number.
16  */
17 #define	SPA_VERSION			28ULL
18 
19 /*
20  * The following are configuration names used in the nvlist describing a pool's
21  * configuration.
22  */
23 #define	ZPOOL_CONFIG_VERSION		"version"
24 #define	ZPOOL_CONFIG_POOL_NAME		"name"
25 #define	ZPOOL_CONFIG_POOL_STATE		"state"
26 #define	ZPOOL_CONFIG_POOL_TXG		"txg"
27 #define	ZPOOL_CONFIG_POOL_GUID		"pool_guid"
28 #define	ZPOOL_CONFIG_CREATE_TXG		"create_txg"
29 #define	ZPOOL_CONFIG_TOP_GUID		"top_guid"
30 #define	ZPOOL_CONFIG_VDEV_TREE		"vdev_tree"
31 #define	ZPOOL_CONFIG_TYPE		"type"
32 #define	ZPOOL_CONFIG_CHILDREN		"children"
33 #define	ZPOOL_CONFIG_ID			"id"
34 #define	ZPOOL_CONFIG_GUID		"guid"
35 #define	ZPOOL_CONFIG_PATH		"path"
36 #define	ZPOOL_CONFIG_DEVID		"devid"
37 #define	ZPOOL_CONFIG_METASLAB_ARRAY	"metaslab_array"
38 #define	ZPOOL_CONFIG_METASLAB_SHIFT	"metaslab_shift"
39 #define	ZPOOL_CONFIG_ASHIFT		"ashift"
40 #define	ZPOOL_CONFIG_ASIZE		"asize"
41 #define	ZPOOL_CONFIG_DTL		"DTL"
42 #define	ZPOOL_CONFIG_STATS		"stats"
43 #define	ZPOOL_CONFIG_WHOLE_DISK		"whole_disk"
44 #define	ZPOOL_CONFIG_ERRCOUNT		"error_count"
45 #define	ZPOOL_CONFIG_NOT_PRESENT	"not_present"
46 #define	ZPOOL_CONFIG_SPARES		"spares"
47 #define	ZPOOL_CONFIG_IS_SPARE		"is_spare"
48 #define	ZPOOL_CONFIG_NPARITY		"nparity"
49 #define	ZPOOL_CONFIG_PHYS_PATH		"phys_path"
50 #define	ZPOOL_CONFIG_L2CACHE		"l2cache"
51 #define	ZPOOL_CONFIG_HOLE_ARRAY		"hole_array"
52 #define	ZPOOL_CONFIG_VDEV_CHILDREN	"vdev_children"
53 #define	ZPOOL_CONFIG_IS_HOLE		"is_hole"
54 #define	ZPOOL_CONFIG_DDT_HISTOGRAM	"ddt_histogram"
55 #define	ZPOOL_CONFIG_DDT_OBJ_STATS	"ddt_object_stats"
56 #define	ZPOOL_CONFIG_DDT_STATS		"ddt_stats"
57 /*
58  * The persistent vdev state is stored as separate values rather than a single
59  * 'vdev_state' entry.  This is because a device can be in multiple states, such
60  * as offline and degraded.
61  */
62 #define	ZPOOL_CONFIG_OFFLINE		"offline"
63 #define	ZPOOL_CONFIG_FAULTED		"faulted"
64 #define	ZPOOL_CONFIG_DEGRADED		"degraded"
65 #define	ZPOOL_CONFIG_REMOVED		"removed"
66 
67 #define	VDEV_TYPE_ROOT			"root"
68 #define	VDEV_TYPE_MIRROR		"mirror"
69 #define	VDEV_TYPE_REPLACING		"replacing"
70 #define	VDEV_TYPE_RAIDZ			"raidz"
71 #define	VDEV_TYPE_DISK			"disk"
72 #define	VDEV_TYPE_FILE			"file"
73 #define	VDEV_TYPE_MISSING		"missing"
74 #define	VDEV_TYPE_HOLE			"hole"
75 #define	VDEV_TYPE_SPARE			"spare"
76 #define	VDEV_TYPE_L2CACHE		"l2cache"
77 
78 /*
79  * pool state.  The following states are written to disk as part of the normal
80  * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE, L2CACHE.  The remaining
81  * states are software abstractions used at various levels to communicate pool
82  * state.
83  */
84 typedef enum pool_state {
85 	POOL_STATE_ACTIVE = 0,		/* In active use		*/
86 	POOL_STATE_EXPORTED,		/* Explicitly exported		*/
87 	POOL_STATE_DESTROYED,		/* Explicitly destroyed		*/
88 	POOL_STATE_SPARE,		/* Reserved for hot spare use	*/
89 	POOL_STATE_L2CACHE,		/* Level 2 ARC device		*/
90 	POOL_STATE_UNINITIALIZED,	/* Internal spa_t state		*/
91 	POOL_STATE_UNAVAIL,		/* Internal libzfs state	*/
92 	POOL_STATE_POTENTIALLY_ACTIVE	/* Internal libzfs state	*/
93 } pool_state_t;
94 
95 struct zfs_data;
96 
97 int zfs_fetch_nvlist(device_t dev, char **nvlist);
98 int zfs_getmdnobj(device_t dev, const char *fsfilename,
99 			       uint64_t *mdnobj);
100 
101 char *zfs_nvlist_lookup_string(char *nvlist, char *name);
102 char *zfs_nvlist_lookup_nvlist(char *nvlist, char *name);
103 int zfs_nvlist_lookup_uint64(char *nvlist, char *name,
104 				   uint64_t *out);
105 char *zfs_nvlist_lookup_nvlist_array(char *nvlist, char *name,
106 					   size_t index);
107 int zfs_nvlist_lookup_nvlist_array_get_nelm(char *nvlist, char *name);
108 
109 #endif	/* ! GRUB_ZFS_HEADER */
110